-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make possible truncation noticable to the user code
- Loading branch information
Showing
8 changed files
with
103 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::{FixedArray, FixedString, ValidLength}; | ||
mod sealed { | ||
pub trait Sealed {} | ||
|
||
impl Sealed for String {} | ||
impl<T> Sealed for Vec<T> {} | ||
} | ||
|
||
/// A sealed helper trait for calling [`FixedArray<T>::from_vector_trunc`] or [`FixedString::from_string_trunc`]. | ||
/// | ||
/// Both of these functions may truncate the input in order to fit it into the provided [`ValidLength`], | ||
/// therefore this trait must be imported in order to make possible truncation made obvious in user code. | ||
pub trait TruncatingInto<T>: sealed::Sealed { | ||
fn trunc_into(self) -> T; | ||
} | ||
|
||
impl<LenT: ValidLength> TruncatingInto<FixedString<LenT>> for String { | ||
fn trunc_into(self) -> FixedString<LenT> { | ||
FixedString::from_string_trunc(self) | ||
} | ||
} | ||
|
||
impl<T, LenT: ValidLength> TruncatingInto<FixedArray<T, LenT>> for Vec<T> { | ||
fn trunc_into(self) -> FixedArray<T, LenT> { | ||
FixedArray::from_vec_trunc(self) | ||
} | ||
} |