Skip to content

Instantly share code, notes, and snippets.

View roneygomes's full-sized avatar
✌️

Roney Gomes roneygomes

✌️
View GitHub Profile
pub trait Write {
// escreve um buffer nesse escritor retornando
// quantos bytes foram escritos em caso de sucesso
fn write(&mut self, buf: &[u8]) -> Result<usize>;
// limpa o escritor, garantindo que qualquer conteúdo
// armazenado em buffers intermediários seja persistido
// no armazenamento final
fn flush(&mut self) -> Result<()>;
use std::io::Write;
use std::io::Result;
#[derive(Debug)]
struct ArrayWrapper {
pub buffer: Vec<u8>,
}
impl Write for ArrayWrapper {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
@roneygomes
roneygomes / rust-polimorfismo-1.rs
Last active November 27, 2021 02:34
a escrita como operação polimórfica
// escrevendo em papel
fn write_on_paper(media: &mut Paper, text: &str);
// escrevendo num computador
fn write_on_computer(media: &mut Computer, text: &str);
// escrevendo na areia
fn write_on_sand(media: &mut Sand, text: &str);
use std::io::Write;
use std::io::Result;
#[derive(Debug)]
struct ArrayWrapper {
pub buffer: Vec<u8>,
}
impl Write for ArrayWrapper {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
Compiling playground v0.0.1 (/playground)
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:22:22
|
22 | fn write(media: &mut Write, text: &str) {
| ^^^^^
|
help: add `dyn` keyword before this trait
|
22 | fn write(media: &mut dyn Write, text: &str) {
fn write(media: &mut dyn Write, text: &str) {
// ...
}
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 1.21s
Running `target/debug/playground`
ArrayWrapper { buffer: [97, 108, 195, 180, 32, 109, 117, 110, 100, 111, 33] }
let mut array_wrapper = ArrayWrapper {
buffer: vec![]
};
let media: &mut dyn Write = &mut array_wrapper;
write(media, "alô mundo!");
let _ = media.write(text_bytes);
// ...
@roneygomes
roneygomes / git aliases
Created November 30, 2021 22:49
my git aliases
[alias]
pr = pull --rebase
ls = log --graph --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --abbrev-commit
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --numstat
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --date=short
clean-branches = !git branch | grep -v \" master$\" | xargs git branch -D
checkpoint = commit -am 'checkpoint'
last-message = log -n 1 --pretty=format:'%n%n%b'