Skip to content

Instantly share code, notes, and snippets.

Avatar
✌️

Roney Gomes roneygomes

✌️
View GitHub Profile
View 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'
View rust-polimorfismo-8.rs
let mut array_wrapper = ArrayWrapper {
buffer: vec![]
};
let media: &mut dyn Write = &mut array_wrapper;
write(media, "alô mundo!");
View rust-polimorfismo-8
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] }
View rust-polimorfismo-7.rs
fn write(media: &mut dyn Write, text: &str) {
// ...
}
View rust-polimorfismo-6
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) {
View rust-polimorfismo-5.rs
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> {
View rust-polimorfismo-4.rs
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> {
View rust-polimorfismo-3.rs
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<()>;
@roneygomes
roneygomes / rust-polimorfismo-2.rs
Last active Nov 27, 2021
temos que colocar alguma coisa no lugar de ???
View rust-polimorfismo-2.rs
fn write(media: &mut ???, text: &str);
// ...