Skip to main content

Ports

Struct Ports 

Source
pub struct Ports {
Show 24 fields pub config: Arc<dyn Config>, pub db: Option<Arc<dyn Database>>, pub auth: Option<Arc<dyn Auth>>, pub mailer: Option<Arc<dyn Mailer>>, pub captcha: Option<Arc<dyn Captcha>>, pub rate_limiter: Option<Arc<dyn RateLimiter>>, pub signer: Option<Arc<dyn Signer>>, pub kv: Option<Arc<dyn KeyValue>>, pub blob: Option<Arc<dyn Blob>>, pub push: Option<Arc<dyn Push>>, pub payments: Option<Arc<dyn Payments>>, pub tracker: Option<Arc<dyn Tracker>>, pub realtime: Option<Arc<dyn Realtime>>, pub text_model: Option<Arc<dyn TextModel>>, pub classifier: Option<Arc<dyn Classifier>>, pub vector_index: Option<Arc<dyn VectorIndex>>, pub embedder: Option<Arc<dyn Embedder>>, pub custom_hostnames: Option<Arc<dyn CustomHostnames>>, pub http: Option<Arc<dyn HttpClient>>, pub clock: Option<Arc<dyn Clock>>, pub id_gen: Option<Arc<dyn IdGen>>, pub defer: Option<Arc<dyn Defer>>, pub dispatcher: Option<Arc<dyn Dispatcher>>, pub tenants: Option<Arc<dyn TenantRouting>>,
}
Expand description

The per-request bundle of resolved port implementations plus the typed config the runtime built from environment/secrets.

Every port is optional: the Cloudflare runtime resolves what the venture’s bindings actually provide and leaves the rest None.

Fields§

§config: Arc<dyn Config>§db: Option<Arc<dyn Database>>§auth: Option<Arc<dyn Auth>>

Who a request’s credentials speak for (issue #153). None is a deployment that cannot identify a caller at all; a module needing one declares Port::Auth and is refused composition here.

§mailer: Option<Arc<dyn Mailer>>§captcha: Option<Arc<dyn Captcha>>§rate_limiter: Option<Arc<dyn RateLimiter>>§signer: Option<Arc<dyn Signer>>§kv: Option<Arc<dyn KeyValue>>§blob: Option<Arc<dyn Blob>>§push: Option<Arc<dyn Push>>§payments: Option<Arc<dyn Payments>>§tracker: Option<Arc<dyn Tracker>>§realtime: Option<Arc<dyn Realtime>>§text_model: Option<Arc<dyn TextModel>>

A text completion by ModelTier, never by vendor (issue #429).

§classifier: Option<Arc<dyn Classifier>>

A typed, calibrated decision by a set of Questions, never by vendor (issue #456) — the sibling of text_model.

§vector_index: Option<Arc<dyn VectorIndex>>

Nearest-neighbour search over tenant-scoped namespaces (issue #561), the output side of embeddings, as text_model is.

§embedder: Option<Arc<dyn Embedder>>

Text into embedding vectors (issue #561), the input side of Ports::vector_index.

§custom_hostnames: Option<Arc<dyn CustomHostnames>>

Custom hostnames a customer owns, served by a venture (issue #590) — Cloudflare for SaaS behind the same trait on every runtime.

§http: Option<Arc<dyn HttpClient>>§clock: Option<Arc<dyn Clock>>§id_gen: Option<Arc<dyn IdGen>>§defer: Option<Arc<dyn Defer>>§dispatcher: Option<Arc<dyn Dispatcher>>

Set by the runtime when the venture mounts sidecar modules. Not a Port, so view_for never copies it and no module can reach it.

§tenants: Option<Arc<dyn TenantRouting>>

How this deployment turns a host into a tenant, and a tenant into its database (TENANT-ROUTING.md §3-§5). None is the no registry deployment — Cloudflare, the browser, and native in development and test — which resolves every host to the implicit tenant and hands back Ports::db.

Not a Port for the same reason dispatcher is not: view_for must never copy it into a module’s view. A module reaches a database through the TenantConn extractor, which can only give it the one the request resolved.

Implementations§

Source§

impl Ports

Source

pub fn empty() -> Self

An empty bundle with no ports resolved and an EmptyConfig.

Source

pub fn with_config(config: Arc<dyn Config>) -> Self

Source

pub fn provides(&self) -> Vec<Port>

The set of ports this bundle actually provides.

Walks Port::ALL and asks Self::has, so a variant added to the enum cannot be left out of the answer: the match in has is exhaustive and the compiler refuses a new one until it is handled. Written out as fifteen ifs, it had already lost one — Port::Auth was missing, so this reported fourteen of fifteen and a bundle with a verifier wired said it had none.

Source

pub fn has(&self, port: Port) -> bool

Whether one port is wired in this bundle.

The exhaustive match is the point. dispatcher and tenants are deliberately absent from Port — no module may reach either — so they have nothing to answer here.

Source

pub fn view_for(&self, module: &dyn Module) -> Self

A copy of this bundle in which every port the module did not declare in requires() or optional() is None, so a module cannot use what it did not declare (issue #3). Undeclared-but-provided ports are logged once per module by Harness::build.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Ports

§

impl !UnwindSafe for Ports

§

impl Freeze for Ports

§

impl Send for Ports

§

impl Sync for Ports

§

impl Unpin for Ports

§

impl UnsafeUnpin for Ports

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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<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