Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(volo-http): refactor client target #470

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 57 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion volo-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-http"
version = "0.2.9"
version = "0.2.10"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down Expand Up @@ -76,6 +76,7 @@ sonic-rs = { workspace = true, optional = true }

[dev-dependencies]
async-stream.workspace = true
libc.workspace = true
serde = { workspace = true, features = ["derive"] }
tokio-test.workspace = true

Expand Down
88 changes: 88 additions & 0 deletions volo-http/src/client/callopt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! Call options for requests
//!
//! See [`CallOpt`] for more details.

use faststr::FastStr;
use metainfo::{FastStrMap, TypeMap};

/// Call options for requests
///
/// It can be set to a [`Client`][Client] or a [`RequestBuilder`][RequestBuilder]. The
/// [`TargetParser`][TargetParser] will handle [`Target`][Target] and the [`CallOpt`] for
/// applying information to the [`Endpoint`].
///
/// [Client]: crate::client::Client
/// [RequestBuilder]: crate::client::RequestBuilder
/// [`TargetParser`]: crate::client::target::TargetParser
#[derive(Debug, Default)]
pub struct CallOpt {
/// `tags` is used to store additional information of the endpoint.
///
/// Users can use `tags` to store custom data, such as the datacenter name or the region name,
/// which can be used by the service discoverer.
pub tags: TypeMap,
/// `faststr_tags` is a optimized typemap to store additional information of the endpoint.
///
/// Use [`FastStrMap`] instead of [`TypeMap`] can reduce the Box allocation.
///
/// This is mainly for performance optimization.
pub faststr_tags: FastStrMap,
}

impl CallOpt {
/// Create a new [`CallOpt`]
#[inline]
pub fn new() -> Self {
Self::default()
}

/// Check if [`CallOpt`] tags contain entry
#[inline]
pub fn contains<T: 'static>(&self) -> bool {
self.tags.contains::<T>()
}

/// Insert a tag into this [`CallOpt`].
#[inline]
pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) {
self.tags.insert(val);
}

/// Insert a tag into this [`CallOpt`] and return self.
#[inline]
pub fn with<T: Send + Sync + 'static>(mut self, val: T) -> Self {
self.tags.insert(val);
self
}

/// Get a reference to a tag previously inserted on this [`CallOpt`].
#[inline]
pub fn get<T: 'static>(&self) -> Option<&T> {
self.tags.get::<T>()
}

/// Check if [`CallOpt`] tags contain entry
#[inline]
pub fn contains_faststr<T: 'static>(&self) -> bool {
self.faststr_tags.contains::<T>()
}

/// Insert a tag into this [`CallOpt`].
#[inline]
pub fn insert_faststr<T: Send + Sync + 'static>(&mut self, val: FastStr) {
self.faststr_tags.insert::<T>(val);
}

/// Insert a tag into this [`CallOpt`] and return self.
#[inline]
pub fn with_faststr<T: Send + Sync + 'static>(mut self, val: FastStr) -> Self {
self.faststr_tags.insert::<T>(val);
self
}

/// Get a reference to a tag previously inserted on this [`CallOpt`].
#[inline]
pub fn get_faststr<T: 'static>(&self) -> Option<&FastStr> {
self.faststr_tags.get::<T>()
}
}
292 changes: 0 additions & 292 deletions volo-http/src/client/discover/mod.rs

This file was deleted.

Loading
Loading