pub struct Uri(/* private fields */);Expand description
URI with validation and type safety
Represents a Uniform Resource Identifier with validation and utility methods. The internal string representation is private to ensure validation.
§Examples
use airsprotocols_mcp::protocol::Uri;
// Valid URI construction
let uri = Uri::new("file:///path/to/file")?;
assert_eq!(uri.scheme(), Some("file"));
assert_eq!(uri.as_str(), "file:///path/to/file");
// Invalid URI fails validation
let result = Uri::new("not-a-uri");
assert!(result.is_err());
// Unchecked construction for trusted sources
let uri = Uri::new_unchecked("custom://internal");Implementations§
Source§impl Uri
impl Uri
Sourcepub fn new(uri: impl Into<String>) -> ProtocolResult<Self>
pub fn new(uri: impl Into<String>) -> ProtocolResult<Self>
Create a new URI with validation
§Errors
Returns ProtocolError::InvalidUri if the URI format is invalid.
Sourcepub fn new_unchecked(uri: impl Into<String>) -> Self
pub fn new_unchecked(uri: impl Into<String>) -> Self
Create URI without validation (for trusted sources)
This should only be used when the URI is known to be valid, such as constants or internally generated URIs.
Sourcepub fn is_file_uri(&self) -> bool
pub fn is_file_uri(&self) -> bool
Check if this is a file URI
Sourcepub fn is_http_uri(&self) -> bool
pub fn is_http_uri(&self) -> bool
Check if this is an HTTP/HTTPS URI
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.