Skip to content

Commit

Permalink
apps(blog): add article
Browse files Browse the repository at this point in the history
  • Loading branch information
augustfengd committed Aug 19, 2024
1 parent 0dce9bf commit 9f6d5e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/blog/content/articles/implementing-the-write-trait.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#+title: Implementing the Write trait
#+categories: programming
#+tags[]: rust
#+date: [2024-08-18 Sun]


Well, I did the Read trait so I gotta do the Write trait right?

#+begin_src rust
use std::io::Write;

struct Foobar {
data: String,
}

impl std::io::Write for Foobar {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let s = std::str::from_utf8(buf).expect("whops");
self.data.push_str(s);
Ok(s.len())
}

fn flush(&mut self) -> std::io::Result<()> {
todo!()
}
}

fn main() {
let mut foobar = Foobar {
data: String::from("helloworld"),
};

let _ = foobar.write(".".as_bytes());
println!("{}", foobar.data)
}
#+end_src
1 change: 1 addition & 0 deletions apps/blog/scripts/linter/linter.cue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"\(#blog_dir)/content/articles/learning-rust-iterators.org": "Learning Rust iterators"
"\(#blog_dir)/content/articles/keeping-a-linear-history-with-github-actions.org": "Keeping a linear history with GitHub Actions"
"\(#blog_dir)/content/articles/implementing-the-read-trait.org": "Implementing the Read trait"
"\(#blog_dir)/content/articles/implementing-the-write-trait.org": "Implementing the Write trait"
"\(#blog_dir)/content/articles/environment-variables-and-volumes-when-building-images-with-docker-compose.org": "Environment variables and volumes when building images with Docker Compose"
"\(#blog_dir)/content/articles/exploring-org-agenda-workflows.org": "Exploring org-agenda workflows"
"\(#blog_dir)/content/articles/digests-from-docker-manifests.org": "Digests from Docker manifests"
Expand Down

0 comments on commit 9f6d5e9

Please sign in to comment.