Skip to main content

RemoteDocument

Struct RemoteDocument 

Source
pub struct RemoteDocument<I = IriBuf, T = Value> {
    pub url: Option<I>,
    pub content_type: Option<MediaTypeBuf>,
    pub context_url: Option<I>,
    pub profile: HashSet<Profile<I>>,
    pub document: T,
}
Expand description

Remote document.

Stores the content of a loaded remote document along with its original URL.

Fields§

§url: Option<I>

The final URL of the loaded document, after eventual redirection.

§content_type: Option<MediaTypeBuf>

The HTTP Content-Type header value of the loaded document, exclusive of any optional parameters.

§context_url: Option<I>

If available, the value of the HTTP Link Header RFC 8288 using the http://www.w3.org/ns/json-ld#context link relation in the response.

If the response’s Content-Type is application/ld+json, the HTTP Link Header is ignored. If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, the loader fails with a multiple context link headers error.

§profile: HashSet<Profile<I>>

Profiles advertised by the document’s media type.

§document: T

The retrieved document.

Implementations§

Source§

impl<I, T> RemoteDocument<I, T>

Source

pub fn new( url: Option<I>, content_type: Option<MediaTypeBuf>, document: T, ) -> Self

Creates a new remote document.

url is the final URL of the loaded document, after eventual redirection. content_type is the HTTP Content-Type header value of the loaded document, exclusive of any optional parameters.

Source

pub fn new_full( url: Option<I>, content_type: Option<MediaTypeBuf>, context_url: Option<I>, profile: HashSet<Profile<I>>, document: T, ) -> Self

Creates a new remote document.

url is the final URL of the loaded document, after eventual redirection. content_type is the HTTP Content-Type header value of the loaded document, exclusive of any optional parameters. context_url is the value of the HTTP Link Header RFC 8288 using the http://www.w3.org/ns/json-ld#context link relation in the response, if any. profile is the value of any profile parameter retrieved as part of the original contentType.

Source

pub fn map<U>(self, f: impl Fn(T) -> U) -> RemoteDocument<I, U>

Maps the content of the remote document.

Source

pub fn try_map<U, E>( self, f: impl Fn(T) -> Result<U, E>, ) -> Result<RemoteDocument<I, U>, E>

Tries to map the content of the remote document.

§Errors

Returns whatever f returns for the contained document.

Source

pub fn map_iris<J>(self, f: impl FnMut(I) -> J) -> RemoteDocument<J, T>
where J: Eq + Hash,

Maps all the IRIs.

Source

pub fn url(&self) -> Option<&I>

Returns a reference to the final URL of the loaded document, after eventual redirection.

Source

pub fn content_type(&self) -> Option<&MediaTypeBuf>

Returns the HTTP Content-Type header value of the loaded document, exclusive of any optional parameters.

Source

pub fn context_url(&self) -> Option<&I>

Returns the value of the HTTP Link Header RFC 8288 using the http://www.w3.org/ns/json-ld#context link relation in the response, if any.

If the response’s Content-Type is application/ld+json, the HTTP Link Header is ignored. If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, the loader fails with a multiple context link headers error.

Source

pub fn document(&self) -> &T

Returns a reference to the content of the document.

Source

pub fn document_mut(&mut self) -> &mut T

Returns a mutable reference to the content of the document.

Source

pub fn into_document(self) -> T

Drops the original URL and returns the content of the document.

Source

pub fn into_url(self) -> Option<I>

Drops the content and returns the original URL of the document.

Source

pub fn set_url(&mut self, url: Option<I>)

Sets the URL of the document.

Source§

impl<I> RemoteDocument<I, Value>

Source

pub fn from_value( url: Option<I>, content_type: Option<MediaTypeBuf>, document: impl Into<Value>, ) -> Self

Creates a remote document from any value convertible into a jstrict::Value.

With the serde_json feature enabled, this also accepts serde_json::Value thanks to the From<serde_json::Value> implementation provided by jstrict.

Source§

impl<I> RemoteDocument<I, Value>

Source

pub fn from_serde_json( url: Option<I>, content_type: Option<MediaTypeBuf>, document: Value, ) -> Self

Available on crate feature serde-json only.

Creates a remote document from a serde_json::Value.

Source

pub fn into_serde_json(self) -> RemoteDocument<I, Value>

Available on crate feature serde-json only.

Consumes the document, returning a RemoteDocument<I, serde_json::Value>.

Source§

impl<I> RemoteDocument<I, Value>

Source

pub fn from_sonic_rs( url: Option<I>, content_type: Option<MediaTypeBuf>, document: &Value, ) -> Self

Available on crate feature sonic-rs only.

Creates a remote document from a sonic_rs::Value.

Source

pub fn into_sonic_rs(self) -> RemoteDocument<I, Value>

Available on crate feature sonic-rs only.

Consumes the document, returning a RemoteDocument<I, sonic_rs::Value>.

Trait Implementations§

Source§

impl<I, B> Borrow<RemoteDocument<I>> for Document<I, B>

Source§

fn borrow(&self) -> &RemoteDocument<I>

Immutably borrows from an owned value. Read more
Source§

impl<I: Clone, T: Clone> Clone for RemoteDocument<I, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug, T: Debug> Debug for RemoteDocument<I, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BorrowUnordered for T

Source§

fn as_unordered(&self) -> &Unordered<T>

Views this value as an Unordered reference.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = !

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

impl<T> WithContext for T
where T: ?Sized,

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more