AzureMarker/shaku
AzureMarker/shaku has 618 GitHub stars and 35 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-24 16:25 UTC. Last push 2026-08-09.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
关于
Compile Time Dependency lnjection Library for Rust
开发工具README.md
原文Shaku
Shaku is a compile time dependency injection Rust library. See the docs for more details, including a getting started guide.
Guides
- General getting started guide, with components (aka singletons)
- Providers (aka transient)
- Submodules
Example
use shaku::{module, Component, Interface, HasComponent};
use std::sync::Arc;
trait Logger: Interface {
fn log(&self, content: &str);
}
trait DateLogger: Interface {
fn log_date(&self);
}
#[derive(Component)]
#[shaku(interface = Logger)]
struct LoggerImpl;
impl Logger for LoggerImpl {
fn log(&self, content: &str) {
println!("{}", content);
}
}
#[derive(Component)]
#[shaku(interface = DateLogger)]
struct DateLoggerImpl {
#[shaku(inject)]
logger: Arc<dyn Logger>,
today: String,
year: usize,
}
impl DateLogger for DateLoggerImpl {
fn log_date(&self) {
self.logger.log(&format!("Today is {}, {}", self.today, self.year));
}
}
module! {
MyModule {
components = [LoggerImpl, DateLoggerImpl],
providers = []
}
}
fn main() {
let module = MyModule::builder()
.with_component_parameters::<DateLoggerImpl>(DateLoggerImplParameters {
today: "Jan 26".to_string(),
year: 2020
})
.build();
let date_logger: &dyn DateLogger = module.resolve_ref();
date_logger.log_date();
}
Component vs Provider
Component represents a single instance of a service, aka a singleton.
Provider is more like a factory for instances. Each time a component is
resolved you will get the same instance. Each time a provider is resolved you
will get a new instance.
For more details on Component and Provider, see the
getting started guide and the
provider getting started guide.
Web Framework Integrations
Shaku provides crates to integrate with the following popular web frameworks:
Minimum Supported Rust Version
Shaku supports the latest stable release of Rust, plus the previous two versions at minimum (but possibly more). Changes to the minimum supported version will be noted in the changelog.
Minimum supported version: 1.88.0
Project Status
The foundation of shaku's API is in place, and now the focus is to mature the project based on user feedback. I (@AzureMarker) am active in the project, but I do not have many major changes of my own planned for the future. Most of the future changes will be based on user feedback.
Acknowledgements
This library started off as "he_di" (later renamed to "shaku") under the guidance of @bgbahoue and @U007D. Their work inspired the current maintainer (@AzureMarker) to continue the library from where they left off.
探索相关项目
加载中…