pub struct Uri(/* private fields */);Expand description
A validated URI string
URIs must follow the format: scheme:path where scheme contains only
alphanumeric characters, plus, period, or hyphen.
§Examples
use turbomcp_protocol::types::domain::Uri;
// Valid URIs
let uri1 = Uri::new("file:///path/to/file.txt").unwrap();
let uri2 = Uri::new("https://example.com").unwrap();
let uri3 = Uri::new("resource://my-resource").unwrap();
// Invalid URI (no scheme)
assert!(Uri::new("not-a-uri").is_err());Implementations§
Source§impl Uri
impl Uri
Sourcepub fn new<S: Into<String>>(uri: S) -> Result<Self, UriError>
pub fn new<S: Into<String>>(uri: S) -> Result<Self, UriError>
Create a new URI with validation
§Errors
Returns an error if the URI format is invalid (missing scheme separator ‘:’)
Sourcepub fn new_unchecked<S: Into<String>>(uri: S) -> Self
pub fn new_unchecked<S: Into<String>>(uri: S) -> Self
Create a URI without validation (use with caution)
This should only be used when you’re certain the URI is valid, such as when deserializing from a trusted source.
Sourcepub fn scheme(&self) -> Option<&str>
pub fn scheme(&self) -> Option<&str>
Get the scheme portion of the URI
§Examples
use turbomcp_protocol::types::domain::Uri;
let uri = Uri::new("https://example.com").unwrap();
assert_eq!(uri.scheme(), Some("https"));Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Convert into the inner String
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Uri
impl<'de> Deserialize<'de> for Uri
Source§fn 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
impl Eq for Uri
impl StructuralPartialEq for Uri
Auto Trait Implementations§
impl Freeze for Uri
impl RefUnwindSafe for Uri
impl Send for Uri
impl Sync for Uri
impl Unpin for Uri
impl UnwindSafe for Uri
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> 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§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.