pub struct UsageTap { /* private fields */ }Expand description
Usage a client has learned of a call so far — the input side, which an
Anthropic stream reports when it opens — and the node the call is charged
to. ModelEvent::EndTurn’s usage supersedes what was reported.
Reporting to a tap nobody made does nothing.
The charge is counted once, by whoever routes the call, through
UsageTap::metered: everything above the client only says where it
goes.
Implementations§
Source§impl UsageTap
impl UsageTap
pub fn new() -> Self
Sourcepub fn tallied_in(self, node: Arc<SpendNode>) -> Self
pub fn tallied_in(self, node: Arc<SpendNode>) -> Self
The call also counted into node, which nothing judges: whoever made
the call reads there what it spent, a call that broke off included.
Sourcepub fn for_attempt(&self) -> Self
pub fn for_attempt(&self) -> Self
A fresh tap for one attempt at the call, charged where this one is.
pub fn charge(&self) -> Option<&Arc<SpendNode>>
pub fn report(&self, usage: Usage)
pub fn reported(&self) -> Option<Usage>
Source§impl UsageTap
impl UsageTap
Sourcepub fn metered(self, stream: ModelStream, also: Option<OnSpent>) -> ModelStream
pub fn metered(self, stream: ModelStream, also: Option<OnSpent>) -> ModelStream
stream, its usage counted once into the node this tap is charged to
and to also.
Trait Implementations§
Auto Trait Implementations§
impl Forget for UsageTap
impl Freeze for UsageTap
impl Move for UsageTap
impl RefUnwindSafe for UsageTapwhere
Atomic<usize>: RefUnwindSafe,
Mutex<Option<Usage>>: RefUnwindSafe,
Atomic<u64>: RefUnwindSafe,
impl Send for UsageTap
impl Sync for UsageTap
impl Unpin for UsageTap
impl UnsafeUnpin for UsageTapwhere
*const ArcInner<Mutex<Option<Usage>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<Usage>>>>: UnsafeUnpin,
*const ArcInner<SpendNode> is !null: UnsafeUnpin,
PhantomData<ArcInner<SpendNode>>: UnsafeUnpin,
impl UnwindSafe for UsageTap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more