Rust 语言学习之旅(4)
instanceOfObj.foo())。Rust 使用:
&self —— 对实例的不可变引用。
&mut self —— 对实例的可变引用。
方法是在一个有 impl 关键字的实现块中定义的
1 年 前
Rust语言之GoF设计模式:Builder建造者模式
};
/// Builder 定义了如何组装一辆汽车。
pub trait Builder {
type OutputType;
fn set_car_type(&mut self
1 年 前
Rust语言之GoF设计模式:中介者Mediator模式
;RefCell<..>> 不推荐这种方法,欺骗 Rust 编译器。 问题: 所有 trait 方法都是只读的:不可变self和不可变参数。 Rc,RefCell在底层被广泛使用
1 年 前
六边形架构:为什么它比 MVC 或Clean架构更好?
get_post(self, post_id: int) -> Optional[Dict[str, Any]]:
pass
def create_post(self
10 个月 前
DCI中场景的另一种实现和思考
场景之前调用的方法, self参数是表示context自身。 例如,甚至可以把 req 添加到 cxt 中,但这样又不表示侵入cxt本身。 可以
10 年 前
Rust语言之GoF设计模式:观察者模式
: impl Observer for A {
fn event(&mut self, ev: &String) {
println!( "Got
1 年 前
Rust 语言学习之旅(5)
: String,
noise: String,
}
impl SeaCreature {
pub fn get_sound(&self) -> &str
1 年 前
Python中实现Treap中的查找、插入和删除
Treap 中。
[code]class Treap:
def _insert(self, node, key, priority):
if node is
2 个月 前
Builder模式与Java语法
RussianUser
;
可能的解决方案: Self typing 解决它的一种方法是添加一个泛型参数User.Builder,指示要返回的类型: public
5 年 前
Rusty类型状态Typestates入门 - rustype
Drone<State>为每个状态实现: impl Drone<Idle> {
pub fn new() -> Self {
Self
2 年 前
Rust语言之GoF设计模式:抽象工厂模式
抽象工厂解决了在不指定具体类的情况下创建整个产品系列的问题。 抽象工厂的抽象接口: lib.rs pub trait Button {
fn press(&self
1 年 前
Rust语言之GoF设计模式:责任链模式
;'a> {
fn set_next(&'a mut self, next: &'a Policeman<'a>);
}
pub struct
1 年 前
Rust语言之GoF设计模式:适配器Adapter
target.rs pub trait Target {
fn request(&self) -> String;
}
pub struct OrdinaryTarget
1 年 前
六边形架构:为什么它比 MVC 或Clean架构更好?
适配器 首先,我们将必要的端口定义为接口或抽象类。这些端口作为适配器必须遵守的协议。 class BlogRepository:
def get_post(self
10 个月 前
在Rust中如何高效实现WebSocket? - ahmadrosid
: SystemTime,
}
impl FileWatcherWebsocket {
pub fn new () -> Self {
let metadata = fs
2 年 前