diff --git a/zerocopy/src/error.rs b/zerocopy/src/error.rs index afdbc03829..3dedc6f469 100644 --- a/zerocopy/src/error.rs +++ b/zerocopy/src/error.rs @@ -436,7 +436,23 @@ pub struct SizeError { } impl SizeError { - pub(crate) fn new(src: Src) -> Self { + /// Constructs a new `SizeError`. + /// + /// This can be used to propagate a size error out of code which knows, + /// out-of-band, that a conversion would fail due to an incorrect source + /// size, without needing to actually perform a failing conversion just to + /// obtain the error. + /// + /// # Examples + /// + /// ``` + /// use zerocopy::error::{ConvertError, SizeError}; + /// + /// let err: SizeError<(), u32> = SizeError::new(()); + /// let err: ConvertError<(), SizeError<(), u32>, ()> = err.into(); + /// ``` + #[inline] + pub fn new(src: Src) -> Self { Self { src, _dst: SendSyncPhantomData::default() } } @@ -595,7 +611,24 @@ pub struct ValidityError { } impl ValidityError { - pub(crate) fn new(src: Src) -> Self { + /// Constructs a new `ValidityError`. + /// + /// This can be used to propagate a validity error out of code which + /// knows, out-of-band, that a conversion would fail due to invalid + /// source data, without needing to actually perform a failing conversion + /// just to obtain the error. + /// + /// # Examples + /// + /// ``` + /// use zerocopy::error::{ConvertError, ValidityError}; + /// use zerocopy::FromBytes; + /// + /// let err: ValidityError<(), bool> = ValidityError::new(()); + /// let err: ConvertError<(), (), ValidityError<(), bool>> = err.into(); + /// ``` + #[inline] + pub fn new(src: Src) -> Self { Self { src, _dst: SendSyncPhantomData::default() } } diff --git a/zerocopy/tests/ui/try_transmute.msrv.stderr b/zerocopy/tests/ui/try_transmute.msrv.stderr index dacbbe8e23..08b62ffc62 100644 --- a/zerocopy/tests/ui/try_transmute.msrv.stderr +++ b/zerocopy/tests/ui/try_transmute.msrv.stderr @@ -18,9 +18,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied @@ -30,9 +30,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy/tests/ui/try_transmute.nightly.stderr b/zerocopy/tests/ui/try_transmute.nightly.stderr index 8ac099d9b9..62dc42f3e4 100644 --- a/zerocopy/tests/ui/try_transmute.nightly.stderr +++ b/zerocopy/tests/ui/try_transmute.nightly.stderr @@ -21,9 +21,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -85,9 +85,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console diff --git a/zerocopy/tests/ui/try_transmute.stable.stderr b/zerocopy/tests/ui/try_transmute.stable.stderr index e6aa785ee9..860cddff90 100644 --- a/zerocopy/tests/ui/try_transmute.stable.stderr +++ b/zerocopy/tests/ui/try_transmute.stable.stderr @@ -21,9 +21,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -85,9 +85,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console diff --git a/zerocopy/tests/ui/try_transmute_mut.msrv.stderr b/zerocopy/tests/ui/try_transmute_mut.msrv.stderr index 8b45a0d9c0..1b87bc8d46 100644 --- a/zerocopy/tests/ui/try_transmute_mut.msrv.stderr +++ b/zerocopy/tests/ui/try_transmute_mut.msrv.stderr @@ -21,9 +21,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied @@ -33,9 +33,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy/tests/ui/try_transmute_mut.nightly.stderr b/zerocopy/tests/ui/try_transmute_mut.nightly.stderr index a260da6b05..06689ec6f1 100644 --- a/zerocopy/tests/ui/try_transmute_mut.nightly.stderr +++ b/zerocopy/tests/ui/try_transmute_mut.nightly.stderr @@ -87,9 +87,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -117,9 +117,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console diff --git a/zerocopy/tests/ui/try_transmute_mut.stable.stderr b/zerocopy/tests/ui/try_transmute_mut.stable.stderr index cad0ec8875..54f9d89754 100644 --- a/zerocopy/tests/ui/try_transmute_mut.stable.stderr +++ b/zerocopy/tests/ui/try_transmute_mut.stable.stderr @@ -87,9 +87,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -117,9 +117,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console diff --git a/zerocopy/tests/ui/try_transmute_ref.msrv.stderr b/zerocopy/tests/ui/try_transmute_ref.msrv.stderr index 32afc9e209..7347c5441e 100644 --- a/zerocopy/tests/ui/try_transmute_ref.msrv.stderr +++ b/zerocopy/tests/ui/try_transmute_ref.msrv.stderr @@ -44,9 +44,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied @@ -56,9 +56,9 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy` | note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy/tests/ui/try_transmute_ref.nightly.stderr b/zerocopy/tests/ui/try_transmute_ref.nightly.stderr index 4401e6fc19..af3c345f9d 100644 --- a/zerocopy/tests/ui/try_transmute_ref.nightly.stderr +++ b/zerocopy/tests/ui/try_transmute_ref.nightly.stderr @@ -106,9 +106,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -136,9 +136,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> src/error.rs:590:45 + --> src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console diff --git a/zerocopy/tests/ui/try_transmute_ref.stable.stderr b/zerocopy/tests/ui/try_transmute_ref.stable.stderr index de3630c06e..501c6e41ab 100644 --- a/zerocopy/tests/ui/try_transmute_ref.stable.stderr +++ b/zerocopy/tests/ui/try_transmute_ref.stable.stderr @@ -106,9 +106,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console @@ -136,9 +136,9 @@ help: the trait `TryFromBytes` is not implemented for `NotZerocopy` (A, B, C, D, E, F, G, H) and $OTHER_TYPES others note: required by a bound in `ValidityError` - --> $WORKSPACE/src/error.rs:590:45 + --> $WORKSPACE/src/error.rs:606:45 | -590 | pub struct ValidityError { +606 | pub struct ValidityError { | ^^^^^^^^^^^^ required by this bound in `ValidityError` = note: the full name for the type has been written to '/long-type-HASH.txt' = note: consider using `--verbose` to print the full type name to the console