Skip to main content

FeatureProfile

Struct FeatureProfile 

Source
pub struct FeatureProfile { /* private fields */ }
Expand description

The set of features a negotiated session has.

A u128 bitset, so allows is a mask and a test — the check every feature-specific code path makes before it runs, and one that must not cost a linear search on the message path.

Implementations§

Source§

impl FeatureProfile

Source

pub const fn empty() -> Self

No features at all. What an unnegotiated session has.

Source

pub fn all() -> Self

Every feature, ignoring revision, capabilities and transport.

Only for tests that need a profile with a known shape. Production code goes through resolve.

Source

pub fn with(self, feature: Feature) -> Self

Adds a feature.

Source

pub fn insert(&mut self, feature: Feature)

Adds a feature in place.

Source

pub fn remove(&mut self, feature: Feature)

Removes a feature.

Source

pub fn allows(self, feature: Feature) -> bool

Whether the session has the feature.

Source

pub const fn len(self) -> u32

How many features the session has.

Source

pub const fn is_empty(self) -> bool

Whether the session has nothing.

Source

pub fn iter(self) -> impl Iterator<Item = Feature>

The features in the profile, in declaration order.

Source

pub fn missing(self) -> impl Iterator<Item = Feature>

The features that are not in the profile, in declaration order.

Source

pub const fn difference(self, other: Self) -> Self

The features this session has that other does not.

Source

pub const fn intersection(self, other: Self) -> Self

The features both sessions have.

Source

pub const fn as_set(self) -> FeatureSet

This profile viewed as a FeatureSet.

The two types share one bit encoding precisely so that this is a copy of a u128 and every comparison between them is a mask test. The alternative — FeatureSet::union_of(self.iter()) — walks all Feature::ALL and calls allows for each, and allows resolves its bit by scanning ALL for a matching name. That is quadratic in the feature count, which is invisible when a decision is made once per message and not when it is made once per primitive on a tools/list of a thousand tools.

Source

pub fn advertised_by_server(self) -> CapabilitySet

The server-side capabilities this session is on, as a set.

This is the answer to “what does this server advertise”, read back out of the same profile every feature gate consults. It is a fold over FEATURES — the same table resolve is a fold over — taking the server_cap of every server-side row the profile allows.

§Why a server’s advertisement is derived and not declared

A server’s InitializeResult has to state its capabilities, and the obvious implementation is a second list beside the feature matrix. That list would be a second thing to update, and the two would disagree the first time a feature was added to FEATURES and not to the list: the gate would switch on a capability the handshake never claimed, and the peer would have been told at connect time not to use it.

Deriving it inverts that. The advertisement is a function of the gate, so it cannot be edited independently of it, and the only way to widen what a server advertises is to widen what it actually does.

Two properties fall out of reading the profile rather than the declaration:

  • Client capabilities are excluded by construction. Their rows are Side::Client with no server_cap, so there is no path by which roots, sampling or elicitation reaches a ServerCapabilities object, which has no field for them.
  • The revision narrows it. A capability survives only if the feature behind it is defined in the negotiated version, so a server that declared everything still advertises only what the agreed revision can name.
§Examples
use protocol_droid::domain::{
    Capability, CapabilitySet, Feature, Negotiation, ProtocolVersion,
    TransportKind, resolve,
};

// A server that declared nothing advertises nothing.
let version = ProtocolVersion::V2025_06_18;
let silent = resolve(Negotiation {
    version,
    client_caps: CapabilitySet::all_for(version),
    server_caps: CapabilitySet::empty(),
    transport: TransportKind::Stdio,
});
assert!(silent.advertised_by_server().is_empty());

// A server that declared tools advertises tools, and nothing a
// client-side-only gate would have switched on.
let loud = resolve(Negotiation {
    version,
    client_caps: CapabilitySet::all_for(version),
    server_caps: CapabilitySet::empty().with(Capability::Tools),
    transport: TransportKind::Stdio,
});
let advertised = loud.advertised_by_server();
assert!(advertised.contains(Capability::Tools));
assert!(!advertised.contains(Capability::ToolsListChanged));
assert!(!advertised.contains(Capability::Sampling), "client-side");

Trait Implementations§

Source§

impl Clone for FeatureProfile

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 Copy for FeatureProfile

Source§

impl Debug for FeatureProfile

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FeatureProfile

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for FeatureProfile

Source§

impl Hash for FeatureProfile

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FeatureProfile

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FeatureProfile

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<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> 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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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