Struct iri_string::template::UriTemplateStr
source · [−]pub struct UriTemplateStr { /* private fields */ }
alloc
only.Expand description
A borrowed 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.
Applied errata
Errata ID 6937 is applied, so single quotes are allowed to appear in an URI template.
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("'quoted'")?;
Implementations
sourceimpl UriTemplateStr
impl UriTemplateStr
sourcepub fn new(s: &str) -> Result<&Self, Error>
pub fn new(s: &str) -> Result<&Self, Error>
Creates a new string.
Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("/users/{username}")?;
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}");
sourceimpl UriTemplateStr
impl UriTemplateStr
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 UriTemplateStr
impl AsRef<UriTemplateStr> for UriTemplateStr
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<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 UriTemplateStr
impl AsRef<str> for UriTemplateStr
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 Debug for UriTemplateStr
impl Debug for UriTemplateStr
sourceimpl<'a, 'de: 'a> Deserialize<'de> for &'a UriTemplateStr
Available on crate feature serde
only.
impl<'a, 'de: 'a> Deserialize<'de> for &'a UriTemplateStr
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 UriTemplateStr
impl Display for UriTemplateStr
sourceimpl<'a> From<&'a UriTemplateStr> for &'a str
impl<'a> From<&'a UriTemplateStr> for &'a str
sourcefn from(s: &'a UriTemplateStr) -> &'a str
fn from(s: &'a UriTemplateStr) -> &'a str
Converts to this type from the input type.
sourceimpl<'a> From<&'a UriTemplateStr> for Cow<'a, UriTemplateStr>
impl<'a> From<&'a UriTemplateStr> for Cow<'a, UriTemplateStr>
sourcefn from(s: &'a UriTemplateStr) -> Self
fn from(s: &'a UriTemplateStr) -> Self
Converts to this type from the input type.
sourceimpl From<&UriTemplateStr> for Arc<UriTemplateStr>
impl From<&UriTemplateStr> for Arc<UriTemplateStr>
sourcefn from(s: &UriTemplateStr) -> Self
fn from(s: &UriTemplateStr) -> Self
Converts to this type from the input type.
sourceimpl From<&UriTemplateStr> for Box<UriTemplateStr>
impl From<&UriTemplateStr> for Box<UriTemplateStr>
sourcefn from(s: &UriTemplateStr) -> Self
fn from(s: &UriTemplateStr) -> Self
Converts to this type from the input type.
sourceimpl From<&UriTemplateStr> for Rc<UriTemplateStr>
impl From<&UriTemplateStr> for Rc<UriTemplateStr>
sourcefn from(s: &UriTemplateStr) -> Self
fn from(s: &UriTemplateStr) -> Self
Converts to this type from the input type.
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 Hash for UriTemplateStr
impl Hash for UriTemplateStr
sourceimpl Ord for UriTemplateStr
impl Ord for UriTemplateStr
sourceimpl PartialEq<&UriTemplateStr> for Cow<'_, str>
impl PartialEq<&UriTemplateStr> for Cow<'_, str>
sourcefn eq(&self, o: &&UriTemplateStr) -> bool
fn eq(&self, o: &&UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<&UriTemplateStr> for str
impl PartialEq<&UriTemplateStr> for str
sourcefn eq(&self, o: &&UriTemplateStr) -> bool
fn eq(&self, o: &&UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<&str> for UriTemplateStr
impl PartialEq<&str> for UriTemplateStr
sourceimpl PartialEq<Cow<'_, str>> for &UriTemplateStr
impl PartialEq<Cow<'_, str>> for &UriTemplateStr
sourceimpl PartialEq<Cow<'_, str>> for UriTemplateStr
impl PartialEq<Cow<'_, str>> for UriTemplateStr
sourceimpl PartialEq<UriTemplateStr> for &str
impl PartialEq<UriTemplateStr> for &str
sourcefn eq(&self, o: &UriTemplateStr) -> bool
fn eq(&self, o: &UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateStr> for Cow<'_, str>
impl PartialEq<UriTemplateStr> for Cow<'_, str>
sourcefn eq(&self, o: &UriTemplateStr) -> bool
fn eq(&self, o: &UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateStr> for UriTemplateStr
impl PartialEq<UriTemplateStr> for UriTemplateStr
sourcefn eq(&self, other: &UriTemplateStr) -> bool
fn eq(&self, other: &UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<UriTemplateStr> for str
impl PartialEq<UriTemplateStr> for str
sourcefn eq(&self, o: &UriTemplateStr) -> bool
fn eq(&self, o: &UriTemplateStr) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<str> for &UriTemplateStr
impl PartialEq<str> for &UriTemplateStr
sourceimpl PartialEq<str> for UriTemplateStr
impl PartialEq<str> for UriTemplateStr
sourceimpl PartialOrd<&UriTemplateStr> for Cow<'_, str>
impl PartialOrd<&UriTemplateStr> for Cow<'_, str>
sourcefn partial_cmp(&self, o: &&UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, o: &&UriTemplateStr) -> 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<&UriTemplateStr> for str
impl PartialOrd<&UriTemplateStr> for str
sourcefn partial_cmp(&self, o: &&UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, o: &&UriTemplateStr) -> 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 UriTemplateStr
impl PartialOrd<&str> for UriTemplateStr
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 &UriTemplateStr
impl PartialOrd<Cow<'_, str>> for &UriTemplateStr
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<Cow<'_, str>> for UriTemplateStr
impl PartialOrd<Cow<'_, str>> for UriTemplateStr
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<UriTemplateStr> for &str
impl PartialOrd<UriTemplateStr> for &str
sourcefn partial_cmp(&self, o: &UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateStr) -> 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<UriTemplateStr> for Cow<'_, str>
impl PartialOrd<UriTemplateStr> for Cow<'_, str>
sourcefn partial_cmp(&self, o: &UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateStr) -> 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<UriTemplateStr> for UriTemplateStr
impl PartialOrd<UriTemplateStr> for UriTemplateStr
sourcefn partial_cmp(&self, other: &UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, other: &UriTemplateStr) -> 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<UriTemplateStr> for str
impl PartialOrd<UriTemplateStr> for str
sourcefn partial_cmp(&self, o: &UriTemplateStr) -> Option<Ordering>
fn partial_cmp(&self, o: &UriTemplateStr) -> 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 &UriTemplateStr
impl PartialOrd<str> for &UriTemplateStr
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<str> for UriTemplateStr
impl PartialOrd<str> for UriTemplateStr
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 UriTemplateStr
impl Serialize for UriTemplateStr
sourceimpl ToOwned for UriTemplateStr
impl ToOwned for UriTemplateStr
type Owned = UriTemplateString
type Owned = UriTemplateString
The resulting type after obtaining ownership.
sourcefn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · sourcefn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Uses borrowed data to replace owned data, usually by cloning. Read more