Skip to main content

ModuleClient

Struct ModuleClient 

Source
pub struct ModuleClient<'a> { /* private fields */ }
Available on crate feature client only.
Expand description

The shared plumbing of every module client.

Implementations§

Source§

impl<'a> ModuleClient<'a>

Source

pub fn new( transport: &'a Transport, peer: &'a Peer, module: ModuleId, from: PartyRef, ) -> Self

Builds a client for one module of one peer.

from is the party this process is speaking as; to is the party at the peer, which defaults to the peer’s only party when it has just one.

Source

pub fn to(self, party: PartyRef) -> Self

Addresses a specific party at the peer, for a platform that hosts several.

Source

pub fn open_routing(self) -> Self

Omits the OCPI-to-* headers, making this an Open Routing Request.

For an Open Routing Request, the TO headers in the request from the requesting party to the Hub MUST be omitted.

Source

pub const fn peer(&self) -> &Peer

The peer this client talks to.

Source

pub fn sender_endpoint(&self) -> Option<SenderEndpoint>

The Sender endpoint of this module, if the peer implements it.

Source

pub fn receiver_endpoint(&self) -> Option<ReceiverEndpoint>

The Receiver endpoint of this module, if the peer implements it.

Source

pub async fn get<T: DeserializeOwned>(&self, url: Url) -> Result<T, OcpiError>

GET {url}, decoding one object.

§Errors

Propagates transport, decoding and OCPI-level errors.

Source

pub async fn get_page<T: DeserializeOwned>( &self, url: Url, ) -> Result<Page<T>, OcpiError>

GET {url}, decoding one page of a list endpoint.

§Errors

Propagates transport, decoding and OCPI-level errors.

Source

pub async fn put<T: Serialize + Validate>( &self, url: Url, body: &T, ) -> Result<(), OcpiError>

PUT {url} with a body, discarding the response payload.

§Errors

Returns OcpiError::Invalid when the body does not conform and the client is configured to check outgoing objects, plus the usual transport and OCPI errors.

Source

pub async fn post<B: Serialize + Validate, T: DeserializeOwned>( &self, url: Url, body: &B, ) -> Result<T, OcpiError>

POST {url} with a body, decoding the response payload.

§Errors

As ModuleClient::put.

Source

pub async fn patch<T>( &self, url: Url, patch: &Patch<T>, ) -> Result<(), OcpiError>

PATCH {url} with a merge patch.

The patch must carry last_updated; the specification’s own example of a 2001 Invalid or missing parameters is a PATCH that does not.

§Errors

Returns OcpiError::Decode when the patch has no last_updated, plus the usual transport and OCPI errors.

Source

pub async fn delete(&self, url: Url) -> Result<(), OcpiError>

DELETE {url}.

§Errors

Propagates transport and OCPI-level errors.

Source

pub async fn get_bridged<T: DeserializeOwned>( &self, url: Url, kind: ObjectKind, ) -> Result<T, OcpiError>

GET {url}, translating the peer’s version into the canonical model.

§Errors

As ModuleClient::get, plus OcpiError::Decode when the peer’s document is not the object this endpoint carries, and OcpiError::Unsupported when this build has no conversions for the peer’s version.

Source

pub async fn put_bridged<T: Serialize + Validate>( &self, url: Url, body: &T, kind: ObjectKind, ) -> Result<(), OcpiError>

PUT {url}, writing the body in the version the peer speaks.

§Errors

As ModuleClient::put, plus OcpiError::Unsupported when this build cannot write the peer’s version.

Source

pub async fn post_bridged<B: Serialize + Validate, T: DeserializeOwned>( &self, url: Url, body: &B, request_kind: Option<ObjectKind>, response_kind: Option<ObjectKind>, ) -> Result<T, OcpiError>

POST {url}, writing the body in the peer’s version and reading the answer back out of it.

request_kind and response_kind are separate because two OCPI endpoints send one object and answer with another — POST {tokens}/{uid}/authorize takes a LocationReferences and returns an AuthorizationInfo.

§Errors

As ModuleClient::post, plus the translation errors of ModuleClient::get_bridged.

Source

pub async fn patch_bridged<T>( &self, url: Url, patch: &Patch<T>, kind: ObjectKind, ) -> Result<(), OcpiError>

PATCH {url} against a peer on another version.

A merge patch is not an object, so it cannot be decoded, converted and re-encoded. It does not have to be: a patch writing only fields the two versions agree about means the same thing in both. One that writes a field they disagree about is refused, with the specification’s own GET → PUT recovery in the message.

§Errors

As ModuleClient::patch, plus OcpiError::Unsupported when the patch writes a field whose shape differs between the two versions.

Source

pub fn list_bridged<T: DeserializeOwned + Send + 'static>( &self, query: PageQuery, kind: ObjectKind, ) -> Result<PageStream<'a, T>, OcpiError>

Crawls a list endpoint, translating every page into the canonical model.

§Errors

As ModuleClient::list.

Source

pub fn list<T: DeserializeOwned + Send + 'static>( &self, query: PageQuery, ) -> Result<PageStream<'a, T>, OcpiError>

Crawls every page of a Sender list endpoint.

The objects arrive exactly as the peer wrote them; see ModuleClient::list_bridged for the version-translating form the typed clients use.

§Errors

Returns OcpiError::NotFound when the peer does not implement the Sender interface.

Source§

impl<'a> ModuleClient<'a>

Source

pub fn list_from<T: DeserializeOwned + Send + 'static>( &self, base: &Url, query: &PageQuery, ) -> PageStream<'a, T>

A paginated crawl starting from an explicit URL rather than the module’s own list endpoint.

Most modules have one list endpoint and list finds it. Payments is the exception: it declares a single ModuleID and then addresses its two interfaces through two different endpoint variables, which version discovery cannot express, so the sub-path has to come from the caller. See SenderEndpoint::payments_terminals.

Trait Implementations§

Source§

impl<'a> Clone for ModuleClient<'a>

Source§

fn clone(&self) -> ModuleClient<'a>

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<'a> Debug for ModuleClient<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ModuleClient<'a>

§

impl<'a> !UnwindSafe for ModuleClient<'a>

§

impl<'a> Freeze for ModuleClient<'a>

§

impl<'a> Send for ModuleClient<'a>

§

impl<'a> Sync for ModuleClient<'a>

§

impl<'a> Unpin for ModuleClient<'a>

§

impl<'a> UnsafeUnpin for ModuleClient<'a>

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> 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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> 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, <T as TryFrom<U>>::Error>

Performs the conversion.
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> 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