Struct iri_string::template::UriTemplateString
source · [−]pub struct UriTemplateString { /* private fields */ }
alloc
only.Expand description
An owned slice of a URI template.
URI Template is defined by RFC 6570.
Note that “URI Template” can also be used for IRI.
Valid values
This type can have a URI template string.
Implementations
sourceimpl UriTemplateString
impl UriTemplateString
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the inner buffer to match its length.
sourcepub fn as_slice(&self) -> &UriTemplateStr
pub fn as_slice(&self) -> &UriTemplateStr
Returns the borrowed IRI string slice.
This is equivalent to &*self
.
sourcepub fn append(&mut self, other: &UriTemplateStr)
pub fn append(&mut self, other: &UriTemplateStr)
Appends the template string.
Methods from Deref<Target = UriTemplateStr>
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the template as a plain &str
.
Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("/users/{username}")?;
assert_eq!(template.as_str(), "/users/{username}");
sourcepub fn expand<'a, S: Spec, C: Context>(
&'a self,
context: &'a C
) -> Result<Expanded<'a, S, C>, Error>
pub fn expand<'a, S: Spec, C: Context>(
&'a self,
context: &'a C
) -> Result<Expanded<'a, S, C>, Error>
Expands the template with the given context.
Examples
#[cfg(feature = "alloc")] {
use iri_string::spec::UriSpec;
use iri_string::template::UriTemplateStr;
use iri_string::template::simple_context::SimpleContext;
let mut context = SimpleContext::new();
context.insert("username", "foo");
let template = UriTemplateStr::new("/users/{username}")?;
let expanded = template.expand::<UriSpec, _>(&context)?;
assert_eq!(
expanded.to_string(),
"/users/foo"
);
You can control allowed characters in the output by changing spec type.
#[cfg(feature = "alloc")] {
use iri_string::spec::{IriSpec, UriSpec};
use iri_string::template::UriTemplateStr;
use iri_string::template::simple_context::SimpleContext;
let mut context = SimpleContext::new();
context.insert("alpha", "\u{03B1}");
let template = UriTemplateStr::new("{?alpha}")?;
assert_eq!(
template.expand::<UriSpec, _>(&context)?.to_string(),
"?alpha=%CE%B1",
"a URI cannot contain Unicode alpha (U+03B1), so it should be escaped"
);
assert_eq!(
template.expand::<IriSpec, _>(&context)?.to_string(),
"?alpha=\u{03B1}",
"an IRI can contain Unicode alpha (U+03B1), so it written as is"
);
Trait Implementations
sourceimpl AsRef<UriTemplateStr> for UriTemplateString
impl AsRef<UriTemplateStr> for UriTemplateString
sourcefn as_ref(&self) -> &UriTemplateStr
fn as_ref(&self) -> &UriTemplateStr
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl AsRef<str> for UriTemplateString
impl AsRef<str> for UriTemplateString
sourceimpl Borrow<UriTemplateStr> for UriTemplateString
impl Borrow<UriTemplateStr> for UriTemplateString
sourcefn borrow(&self) -> &UriTemplateStr
fn borrow(&self) -> &UriTemplateStr
Immutably borrows from an owned value. Read more
sourceimpl Borrow<str> for UriTemplateString
impl Borrow<str> for UriTemplateString
sourceimpl Clone for UriTemplateString
impl Clone for UriTemplateString
sourcefn clone(&self) -> UriTemplateString
fn clone(&self) -> UriTemplateString
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for UriTemplateString
impl Debug for UriTemplateString
sourceimpl Default for UriTemplateString
impl Default for UriTemplateString
sourcefn default() -> UriTemplateString
fn default() -> UriTemplateString
Returns the “default value” for a type. Read more
sourceimpl Deref for UriTemplateString
impl Deref for UriTemplateString
type Target = UriTemplateStr
type Target = UriTemplateStr
The resulting type after dereferencing.
sourcefn deref(&self) -> &UriTemplateStr
fn deref(&self) -> &UriTemplateStr
Dereferences the value.
sourceimpl<'de> Deserialize<'de> for UriTemplateString
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for UriTemplateString
serde
only.sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for UriTemplateString
impl Display for UriTemplateString
sourceimpl From<&UriTemplateStr> for UriTemplateString
impl From<&UriTemplateStr> for UriTemplateString
sourcefn from(s: &UriTemplateStr) -> Self
fn from(s: &UriTemplateStr) -> Self
Converts to this type from the input type.
sourceimpl From<UriTemplateString> for Box<UriTemplateStr>
impl From<UriTemplateString> for Box<UriTemplateStr>
sourcefn from(s: UriTemplateString) -> Box<UriTemplateStr>
fn from(s: UriTemplateString) -> Box<UriTemplateStr>
Converts to this type from the input type.
sourceimpl<'a> From<UriTemplateString> for Cow<'a, UriTemplateStr>
impl<'a> From<UriTemplateString> for Cow<'a, UriTemplateStr>
sourcefn from(s: UriTemplateString) -> Cow<'a, UriTemplateStr>
fn from(s: UriTemplateString) -> Cow<'a, UriTemplateStr>
Converts to this type from the input type.
sourceimpl From<UriTemplateString> for String
impl From<UriTemplateString> for String
sourcefn from(s: UriTemplateString) -> Self
fn from(s: UriTemplateString) -> Self
Converts to this type from the input type.
sourceimpl FromStr for UriTemplateString
impl FromStr for UriTemplateString
sourceimpl Hash for UriTemplateString
impl Hash for UriTemplateString
sourceimpl Ord for UriTemplateString
impl Ord for UriTemplateString
sourcefn cmp(&self, other: &UriTemplateString) -> Ordering
fn cmp(&self, other: &UriTemplateString) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<&str> for UriTemplateString
impl PartialEq<&str> for UriTemplateString
sourceimpl PartialEq<Cow<'_, str>> for UriTemplateString
impl PartialEq<Cow<'_, str>> for UriTemplateString
sourceimpl PartialEq<String> for UriTemplateString
impl PartialEq<String> for UriTemplateString
sourceimpl PartialEq<UriTemplateString> for &str
impl PartialEq<UriTemplateString> for &str
sourcefn eq(&self, o: &UriTemplateString) -> bool
fn eq(&self, o: &UriTemplateString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateString> for Cow<'_, str>
impl PartialEq<UriTemplateString> for Cow<'_, str>
sourcefn eq(&self, o: &UriTemplateString) -> bool
fn eq(&self, o: &UriTemplateString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateString> for String
impl PartialEq<UriTemplateString> for String
sourcefn eq(&self, o: &UriTemplateString) -> bool
fn eq(&self, o: &UriTemplateString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateString> for UriTemplateString
impl PartialEq<UriTemplateString> for UriTemplateString
sourcefn eq(&self, other: &UriTemplateString) -> bool
fn eq(&self, other: &UriTemplateString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateString> for str
impl PartialEq<UriTemplateString> for str
sourcefn eq(&self, o: &UriTemplateString) -> bool
fn eq(&self, o: &UriTemplateString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<str> for UriTemplateString
impl PartialEq<str> for UriTemplateString
sourceimpl PartialOrd<&str> for UriTemplateString
impl PartialOrd<&str> for UriTemplateString
sourcefn partial_cmp(&self, o: &&str) -> Option<Ordering>
fn partial_cmp(&self, o: &&str) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<Cow<'_, str>> for UriTemplateString
impl PartialOrd<Cow<'_, str>> for UriTemplateString
sourcefn partial_cmp(&self, o: &Cow<'_, str>) -> Option<Ordering>
fn partial_cmp(&self, o: &Cow<'_, str>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<String> for UriTemplateString
impl PartialOrd<String> for UriTemplateString
sourcefn partial_cmp(&self, o: &String) -> Option<Ordering>
fn partial_cmp(&self, o: &String) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<UriTemplateString> for &str
impl PartialOrd<UriTemplateString> for &str
sourcefn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<UriTemplateString> for Cow<'_, str>
impl PartialOrd<UriTemplateString> for Cow<'_, str>
sourcefn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<UriTemplateString> for String
impl PartialOrd<UriTemplateString> for String
sourcefn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<UriTemplateString> for UriTemplateString
impl PartialOrd<UriTemplateString> for UriTemplateString
sourcefn partial_cmp(&self, other: &UriTemplateString) -> Option<Ordering>
fn partial_cmp(&self, other: &UriTemplateString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<UriTemplateString> for str
impl PartialOrd<UriTemplateString> for str
sourcefn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateString) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<str> for UriTemplateString
impl PartialOrd<str> for UriTemplateString
sourcefn partial_cmp(&self, o: &str) -> Option<Ordering>
fn partial_cmp(&self, o: &str) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for UriTemplateString
impl Serialize for UriTemplateString
sourceimpl TryFrom<&[u8]> for UriTemplateString
impl TryFrom<&[u8]> for UriTemplateString
sourceimpl TryFrom<&str> for UriTemplateString
impl TryFrom<&str> for UriTemplateString
sourceimpl TryFrom<String> for UriTemplateString
impl TryFrom<String> for UriTemplateString
impl Eq for UriTemplateString
impl StructuralEq for UriTemplateString
impl StructuralPartialEq for UriTemplateString
Auto Trait Implementations
impl RefUnwindSafe for UriTemplateString
impl Send for UriTemplateString
impl Sync for UriTemplateString
impl Unpin for UriTemplateString
impl UnwindSafe for UriTemplateString
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
sourcefn try_to_string(&self) -> Result<String, TryReserveError>
Available on crate feature alloc
only.
fn try_to_string(&self) -> Result<String, TryReserveError>
alloc
only.ToString::to_string
, but without panic on OOM.