Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
playX18 committed Jan 27, 2025
1 parent de56f76 commit 04e8498
Showing 1 changed file with 0 additions and 81 deletions.
81 changes: 0 additions & 81 deletions core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,88 +292,7 @@ impl<T: MaxEncodedLen, E, const N: usize> MaxEncodedLen for LimitedVec<T, E, N>
N * T::max_encoded_len()
}
}
/*
/// Limited len string.
/// `E` is overflow error type.
/// `N` is max len which a string can have.
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct LimitedString<E, const N: usize>(String, PhantomData<E>);
impl<E, const N: usize> LimitedString<E, N> {
/// Creates new empty limited string.
pub const fn new() -> Self {
Self(String::new(), PhantomData)
}

/// Returns length of the string.
pub fn len(&self) -> usize {
self.0.len()
}
/// Returns true if the string is empty.
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Convert string to bytes.
///
/// Asserts that limit for bytes is greater or equal to the string limit.
pub fn into_bytes<U: Default + Debug, const LIMIT: usize>(self) -> LimitedVec<u8, U, LIMIT> {
assert!(LIMIT >= N);
LimitedVec::try_from(self.0.into_bytes()).expect("must succeed")
}
pub fn into_bytes_unchecked(self) -> Vec<u8> {
self.0.into_bytes()
}
}
impl<E, const N: usize> AsRef<str> for LimitedString<E, N> {
fn as_ref(&self) -> &str {
&self.0
}
}
impl<E, const N: usize> AsRef<String> for LimitedString<E, N> {
fn as_ref(&self) -> &String {
&self.0
}
}
impl<E, const N: usize> MaxEncodedLen for LimitedString<E, N> {
fn max_encoded_len() -> usize {
N * size_of::<char>()
}
}
impl<E: Default, const N: usize> TryFrom<String> for LimitedString<E, N> {
type Error = E;
fn try_from(x: String) -> Result<Self, Self::Error> {
(x.len() <= N).then_some(()).ok_or_else(E::default)?;
Ok(Self(x, PhantomData))
}
}
impl<E, const N: usize> From<LimitedString<E, N>> for String {
fn from(x: LimitedString<E, N>) -> Self {
x.0
}
}
impl<E, const N: usize> Display for LimitedString<E, N> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl<E, const N: usize> Debug for LimitedString<E, N> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
*/
/// Max memory size, which runtime can allocate at once.
/// Substrate allocator restrict allocations bigger then 512 wasm pages at once.
/// See more information about:
Expand Down

0 comments on commit 04e8498

Please sign in to comment.