pub struct Text<const N: usize>(/* private fields */);Expand description
A string with the maximum length OICP’s property table gives for its field.
N is that maximum. Over-long values arrive — a peer that sends a 60-character city name
must not make the surrounding page undecodable — and Validate::validate reports them;
Text::new refuses to build one.
use oicp_kit::types::{Text, Validate};
let city = Text::<50>::new("Berlin")?;
assert_eq!(city.as_str(), "Berlin");
// Too long to construct…
assert!(Text::<3>::new("Berlin").is_err());
// …but it still decodes, and is reported.
let arrived: Text<3> = serde_json::from_str(r#""Berlin""#)?;
assert!(arrived.validate().is_err());Implementations§
Source§impl<const N: usize> Text<N>
impl<const N: usize> Text<N>
Sourcepub const MAX: usize = N
pub const MAX: usize = N
The maximum length of this field, per the specification’s property table.
Sourcepub fn new(value: impl Into<String>) -> Result<Self, TextError>
pub fn new(value: impl Into<String>) -> Result<Self, TextError>
Builds a value, refusing one that is already out of spec.
§Errors
Returns TextError::TooLong when the value exceeds N characters.
Sourcepub fn new_unchecked(value: impl Into<String>) -> Self
pub fn new_unchecked(value: impl Into<String>) -> Self
Accepts value without checking its length; Validate reports it.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
The text, consuming the wrapper.
Trait Implementations§
Source§impl<'de, const N: usize> Deserialize<'de> for Text<N>
impl<'de, const N: usize> Deserialize<'de> for Text<N>
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<const N: usize> Eq for Text<N>
Source§impl<const N: usize> JsonSchema for Text<N>
Available on crate feature schema only.
impl<const N: usize> JsonSchema for Text<N>
Available on crate feature
schema only.Source§fn json_schema(_g: &mut SchemaGenerator) -> Schema
fn json_schema(_g: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl<const N: usize> Ord for Text<N>
impl<const N: usize> Ord for Text<N>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<const N: usize> PartialOrd for Text<N>
impl<const N: usize> PartialOrd for Text<N>
impl<const N: usize> StructuralPartialEq for Text<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Text<N>
impl<const N: usize> RefUnwindSafe for Text<N>
impl<const N: usize> Send for Text<N>
impl<const N: usize> Sync for Text<N>
impl<const N: usize> Unpin for Text<N>
impl<const N: usize> UnsafeUnpin for Text<N>
impl<const N: usize> UnwindSafe for Text<N>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
Compare self to
key and return true if they are equal.