Welcome to my blog! Here you can find my thoughts on various topics, including programming, technology, and life.
I hope you enjoy your stay!
Welcome to my blog! Here you can find my thoughts on various topics, including programming, technology, and life.
I hope you enjoy your stay!
Using Error Wrapping An error often “bubbles up” a call chain of multiple functions. In other words, a function receives an error and passes it back to its caller through a return value. The caller might do the same, and so on, until a function up the call chain handles or logs the error. An error can be “wrapped” around another error using fmt.Errorf() and the special formatting verb %w. ...
这里简单总结一下三种组合方式: interface 中嵌套 interface struct 中嵌套 struct struct 中嵌套 interface interface 中嵌套 interface 这种组合方式体现了接口隔离原则(ISP)和接口组合原则, 通过接口嵌套,我们可以构建更大的接口 // 基础读接口 type Reader interface { Read(p []byte) (n int, err error) } // 基础写接口 type Writer interface { Write(p []byte) (n int, err error) } // 组合接口 type ReadWriter interface { Reader // 嵌套 Reader 接口 Writer // 嵌套 Writer 接口 } struct 中嵌套 struct 这种组合方式体现了组合优于继承12的原则,是 Go 中实现代码复用的重要方式 // 地址信息 type Address struct { Street string City string Country string } // 用户信息 type User struct { Name string Age int Address // 嵌套 Address struct } // 使用示例 func main() { user := User{ Name: "张三", Age: 25, Address: Address{ Street: "中关村大街", City: "北京", Country: "中国", }, } // 可以直接访问嵌套字段 fmt.Println(user.Street) // 输出: 中关村大街 } struct 中嵌套 interface 这种组合方式体现了依赖倒置原则(DIP),常用于策略模式的实现 ...
Summary 这篇文章记录几个我非常喜欢的 Chrome 插件 PrintFriendly1 Make web pages printer-friendly and convert them to PDFs. Easily remove ads and navigation, and customize what you print or PDF. ...
05 Vectors fn array_and_vec() -> ([i32; 4], Vec<i32>) { let a = [10, 20, 30, 40]; // Array // TODO: Create a vector called `v` which contains the exact same elements as in the array `a`. // Use the vector macro. // let v = ??? (a, v) } 这里有几种写法,首先想到的肯定是用一个类似于 for 循环的结构类循环赋值 这里总结一下 Rust 中常见的迭代器 for item in list 会调用 into_iter(),消耗 list 的所有权 for item in &list 会调用 iter(),遍历 list 的引用 for item in &mut list 会调用 iter_mut(),遍历 list 的可变引用 如果想要获取 index, 可以使用 enumerate() 方法: ...
Concepts Each workspace contains its own single root node Each non-leaf node is called a “Container” Each container can contain arbitrary number of children nodes Windows are the only possible leaf nodes. Windows contain zero children nodes Every container has two properties: Layout (Possible values: tiles, accordion) Orientation (Possible values: horizontal, vertical) Some examples: In total, AeroSpace provides 4 possible layouts: h_tiles horizontal tiles (in i3, it’s called “horizontal split”) v_tiles vertical tiles (in i3, it’s called “vertical split”) h_accordion horizontal accordion (analog of i3’s “tabbed layout”) v_accordion vertical accordion (analog of i3’s “stacked layout”) Accordion is a layout where windows are placed on top of each other. ...