Struct UriTemplateStr Copy item path Source pub struct UriTemplateStr { }
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'" )? ;
Creates a new string.
§ Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("/users/{username}" )? ;
Creates a new string without validation.
This does not validate the given string, so it is caller’s
responsibility to ensure the given string is valid.
§ Safety
The given string must be syntactically valid as Self
type.
If not, any use of the returned value or the call of this
function itself may result in undefined behavior.
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}" );
Returns the template string length.
§ Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("/users/{username}" )? ;
assert_eq! (template.len(), "/users/{username}" .len());
Returns whether the string is empty.
§ Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("/users/{username}" )? ;
assert! (!template.is_empty());
let empty = UriTemplateStr::new("" )? ;
assert! (empty.is_empty());
Expands the template with the given context.
§ Examples
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.
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"
);
Expands the template into a string, with the given dynamic context.
This is basically expand_dynamic
method
that returns an owned string instead of writing to the given writer.
See the documentation for DynamicContext
for usage.
§ Examples
use iri_string::template::UriTemplateStr;
use iri_string::spec::UriSpec;
struct MyContext<'a > {
}
let mut context = MyContext {
target: "/posts/1" ,
username: Some ("the_admin" ),
username_visited: false ,
};
let template = UriTemplateStr::new("{+target}{?username}" )? ;
let s = template.expand_dynamic_to_string::<UriSpec, _ >(&mut context)? ;
assert_eq! (s, "/posts/1?username=the_admin" );
assert! (context.username_visited);
Returns an iterator of variables in the template.
§ Examples
use iri_string::template::UriTemplateStr;
let template = UriTemplateStr::new("foo{/bar*,baz:4}{?qux}{&bar*}" )? ;
let mut vars = template.variables();
assert_eq! (vars.next().map(|var| var.as_str()), Some ("bar" ));
assert_eq! (vars.next().map(|var| var.as_str()), Some ("baz" ));
assert_eq! (vars.next().map(|var| var.as_str()), Some ("qux" ));
assert_eq! (vars.next().map(|var| var.as_str()), Some ("bar" ));
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value.
Read more Formats the value using the given formatter.
Read more Formats the value using the given formatter.
Read more Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more Converts the given value to a
String
.
Read more