Skip to main content

RepeMethods

Trait RepeMethods 

Source
pub trait RepeMethods: MethodsDeclared {
    const REPE_METHOD_SIGNATURES: &'static [(&'static str, &'static str)];
    const REPE_ACCESSOR_ENDPOINTS: &'static [&'static str] = _;
    const REPE_LISTING_NEEDS_EXCLUSIVE: bool = _;
    const REPE_SHARED_SERVES_BODIES: bool = true;

    // Required method
    fn repe_call_into(
        &mut self,
        segments: &[&str],
        body: Option<RequestBody<'_>>,
        out: &mut ResponseBody<'_>,
    ) -> StructResult<()>;

    // Provided method
    fn repe_call_shared_into(
        &self,
        segments: &[&str],
        body: Option<RequestBody<'_>>,
        out: &mut ResponseBody<'_>,
    ) -> Option<StructResult<()>> { ... }
}
Expand description

Method table for a struct whose methods are declared with #[repe::methods] on an inherent impl block.

Generated by the attribute macro, which sees every signature in the block and so cannot fall behind the type the way a hand-maintained #[repe(methods(..))] list can. #[derive(RepeStruct)] dispatches path segments that match no field through this table when the struct carries the #[repe(methods)] marker.

Implementing this by hand is supported but unusual; the macro exists so the signatures stay derived from the impl block.

Required Associated Constants§

Source

const REPE_METHOD_SIGNATURES: &'static [(&'static str, &'static str)]

(endpoint, signature) pairs published in the whole-struct listing.

Provided Associated Constants§

Source

const REPE_ACCESSOR_ENDPOINTS: &'static [&'static str] = _

Endpoints in this table that are field-shaped: served by a getter/setter pair (#[repe(get = "...")] / #[repe(set = "...")]) rather than by an argument list.

They are deliberately absent from REPE_METHOD_SIGNATURES, because they have no signature to publish: a client reads and writes one the way it reads and writes a field, so the whole-struct listing shows each one’s current value rather than a signature string. The derived listing reads those values back through repe_call_into, or through repe_call_shared_into when it is being served under a shared borrow.

Defaults to empty, so a hand-written impl need not mention it. One invariant comes with listing a name here, and the derived listing relies on it: repe_call_into must answer segments = &[name], body = None with the endpoint’s value. A name the table cannot dispatch turns every whole-struct read into that name’s error. #[repe::methods] upholds it by construction, because it emits this list from the getters it generated arms for. The shared-borrow listing asks the same question of repe_call_shared_into, where a None is not a failure — it declines the whole listing to the exclusive path.

Source

const REPE_LISTING_NEEDS_EXCLUSIVE: bool = _

Whether the whole-struct listing must be served exclusively because some entry in it can only be read through &mut self.

This is the one question the shared listing has to settle before it runs anything, and it is why it is a const rather than a check per entry. A listing is the one read that composes many others; a decline discovered partway through leaves the entries before it already invoked, and the exclusive retry invokes them again. A &self getter over a read counter would report the second call.

Only the getter half of a field-shaped endpoint can force it. Fields serialize, published signatures are string literals, and a nested child declines before writing anything of its own — none of those is a call. So this is true exactly when some accessor’s getter takes &mut self.

The default is the conservative one: any accessor at all forces the exclusive path, which is what a hand-written table gets for free. #[repe::methods] overrides it with the answer it computed from the receivers it has already seen, so a struct whose computed values are pure reads keeps its shared listing — and so does every ancestor that nests it, since a child’s decline propagates.

Overriding it is a promise. Setting it to false asserts that repe_call_shared_into answers segments = &[name], body = None with Some(..) for every name in REPE_ACCESSOR_ENDPOINTS. A table that breaks that promise still produces a correct response — the listing rewinds and retries exclusively — but the getters that ran before the decline run a second time, which is the double invocation this const exists to rule out.

Source

const REPE_SHARED_SERVES_BODIES: bool = true

Whether any endpoint in this table can answer a body-carrying frame through repe_call_shared_into.

The table half of RepeStruct::REPE_SHARED_SERVES_BODIES, which ORs this with what the struct’s own fields and children say. Three shapes here can answer one: a &self method that takes arguments, a &self setter, and a read-only accessor, whose refusal needs no exclusive borrow to give.

The default is true, which is never wrong — only, for a table that serves no body, slower than it needs to be.

Required Methods§

Source

fn repe_call_into( &mut self, segments: &[&str], body: Option<RequestBody<'_>>, out: &mut ResponseBody<'_>, ) -> StructResult<()>

Invoke the method named by segments[0], writing its result into out.

segments is the remaining path relative to the struct root, so error paths match the ones RepeStruct::repe_handle_into produces for fields. Returns StructError::InvalidPath when no method matches.

Provided Methods§

Source

fn repe_call_shared_into( &self, segments: &[&str], body: Option<RequestBody<'_>>, out: &mut ResponseBody<'_>, ) -> Option<StructResult<()>>

Shared-borrow counterpart of repe_call_into, mirroring RepeStruct::repe_shared_into and carrying the same two obligations: answer identically, and decline without writing.

#[repe::methods] serves every &self method here — including one taking arguments, which is a call rather than a mutation however the frame is shaped — along with the getter half of a &self accessor, and declines everything else.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§