pub struct BoundedString(/* private fields */);Expand description
A length-bounded string (max 200 chars / 512 bytes).
Used for note (personal) and payer_note (payer-provided) fields on
payments. Construction validates that the string is within limits;
deserialization rejects strings that exceed either limit.
For untrusted external input that should be silently truncated rather than
rejected, use BoundedString::truncate.
Implementations§
Source§impl BoundedString
impl BoundedString
Sourcepub fn new(s: String) -> Result<BoundedString, StringTooLong>
pub fn new(s: String) -> Result<BoundedString, StringTooLong>
Constructs a bounded string, returning StringTooLong if it’s empty
or exceeds limits.
Sourcepub fn truncate(s: String) -> Option<BoundedString>
pub fn truncate(s: String) -> Option<BoundedString>
Silently truncate a string to fit within limits.
Truncates by character count first, then by byte count. Returns None
if the result is empty after truncation.
Use this for untrusted external input (e.g. inbound LNURL comments, BOLT12 payer notes) where rejecting would cause payment failures.
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consumes and returns the inner string.
Trait Implementations§
Source§impl Clone for BoundedString
impl Clone for BoundedString
Source§fn clone(&self) -> BoundedString
fn clone(&self) -> BoundedString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoundedString
impl Debug for BoundedString
Source§impl<'de> Deserialize<'de> for BoundedString
impl<'de> Deserialize<'de> for BoundedString
Source§fn deserialize<D>(
deserializer: D,
) -> Result<BoundedString, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<BoundedString, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for BoundedString
impl Display for BoundedString
Source§impl FromStr for BoundedString
impl FromStr for BoundedString
Source§type Err = StringTooLong
type Err = StringTooLong
Source§fn from_str(s: &str) -> Result<BoundedString, <BoundedString as FromStr>::Err>
fn from_str(s: &str) -> Result<BoundedString, <BoundedString as FromStr>::Err>
s to return a value of this type. Read moreSource§impl Hash for BoundedString
impl Hash for BoundedString
Source§impl PartialEq for BoundedString
impl PartialEq for BoundedString
Source§impl Serialize for BoundedString
impl Serialize for BoundedString
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl TryFrom<String> for BoundedString
impl TryFrom<String> for BoundedString
Source§type Error = StringTooLong
type Error = StringTooLong
Source§fn try_from(
s: String,
) -> Result<BoundedString, <BoundedString as TryFrom<String>>::Error>
fn try_from( s: String, ) -> Result<BoundedString, <BoundedString as TryFrom<String>>::Error>
impl Eq for BoundedString
impl StructuralPartialEq for BoundedString
Auto Trait Implementations§
impl Freeze for BoundedString
impl RefUnwindSafe for BoundedString
impl Send for BoundedString
impl Sync for BoundedString
impl Unpin for BoundedString
impl UnsafeUnpin for BoundedString
impl UnwindSafe for BoundedString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.