-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c79f6b4
commit d425fe7
Showing
6 changed files
with
65 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
# Taller Oxidar LS | ||
# Oxidar | ||
¡Bienvenido a **Oxidar**! El objetivo de este curso es aprender Rust creando un proyecto desde cero. El curso está dividido en varias etapas donde iremos agregando nuevas funcionalidades al proyecto, cada una introduciendo un nuevo concepto o un desafío con lo que ya se vio hasta el momento. | ||
|
||
## 1. Setup Your Project | ||
## Herramientas | ||
|
||
In this stage, we'll setup command line app that replies with a standard hello world message. | ||
### cargo | ||
|
||
The tester will execute your program like this: | ||
`cargo` es el gestor de paquetes de Rust. Además de gestionar los paquetes, con `cargo` podemos correr tests, construir el proyecto y ejecutar nuestro programa. Los comandos que más utilizaremos son: | ||
|
||
```shell | ||
$ ./your_program | ||
``` | ||
- `cargo run -- <args>`: Corre el proyecto pasando como argumentos `<args>`. | ||
- `cargo test`: Corre los tests. | ||
- `cargo add <nombre_de_dependencia>`: Agrega al `Cargo.toml` la dependencia `<nombre_de_dependencia>` | ||
|
||
<<<<<<< Updated upstream | ||
It then expects to receive a "Hello Rust!" on the standard output. | ||
======= | ||
### crates.io | ||
>>>>>>> Stashed changes | ||
## 2. Write header section | ||
[crates.io](https://crates.io) es el sitio donde se alojan todos los crates públicos o herramientas de líneas de comando que podemos utilizar para construir nuestro proyecto. Generalmente cuando necesitamos una dependencia la solemos buscar aquí. | ||
|
||
## 3. Write question section | ||
En esta página no sólo encontraremos el listado de crates disponibles para utilizar. También encontraremos documentación de los crates (si el autor se molestó en crearla) y su código de fuente. | ||
|
||
## 4. Write answer section | ||
### clippy | ||
|
||
## 5. Parse header section | ||
`clippy` es el linter oficial de Rust. Esta herramienta nos sirve para marcar potenciales errores y estilar el código de forma correcta. | ||
|
||
## 6. Parse question section | ||
### rust-analizer | ||
|
||
## 7. Parse compressed packet | ||
[rust-analizer](https://rust-analyzer.github.io/) es una implementación del [Languange Server Protocol](https://microsoft.github.io/language-server-protocol/) para Rust. El mismo nos provee auto-completado de código entre otras cosas útiles para hacer nuestra vida un poco más sencilla. | ||
|
||
## 8. Forwarding Server | ||
### Visual Studio Code | ||
|
||
Visual Studio Code tiene gran soporte para Rust. | ||
|
||
Te recomendamos instalarte los siguientes plug-ins: | ||
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) | ||
> El mejor amigo de todos los rustaceans. Te va a recomendar mejores practicas, detectar patrones y darte explicaciones de como hacer tu codigo más idiomatico. | ||
- [Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) | ||
> Highlight y formatting para el formato de configuraciones más usado por la comunidad. | ||
- [Dependi](https://marketplace.visualstudio.com/items?itemName=fill-labs.dependi) | ||
> Tu compañero para mantener tus dependencias al dia y acceder a su documentación. | ||
|
||
## Corriendo el proyecto | ||
|
||
Para probar el proyecto, corre `cargo run`. Después de la compilación deberías ver el mensaje `Hello, world!` en la pantalla. | ||
|
||
|
||
Cambia el mensaje a "Hola, Oxidar!" para pasar el primer nivel. | ||
|
||
Exitos! |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,3 @@ | ||
use std::fs::{self, DirEntry}; | ||
use std::io::Error; | ||
|
||
const ERROR_LISTING_FILES: &str = "there was an error listing files"; | ||
|
||
#[derive(Default)] | ||
struct Options { | ||
all: bool, | ||
} | ||
|
||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
|
||
let mut options = Options::default(); | ||
|
||
for arg in &args { | ||
if arg == "-a" || arg == "--all" { | ||
options.all = true; | ||
} | ||
} | ||
|
||
let path = args.last().map(|s| s.as_str()).unwrap_or("."); | ||
let paths = fs::read_dir(path).expect(ERROR_LISTING_FILES); | ||
|
||
let mut dir_entries: Vec<String> = paths | ||
.into_iter() | ||
.collect::<Result<Vec<DirEntry>, Error>>() | ||
.expect(ERROR_LISTING_FILES) | ||
.into_iter() | ||
.filter_map(|f| f.file_name().into_string().ok()) | ||
.collect(); | ||
|
||
dir_entries.sort(); | ||
|
||
let hidden_files: Vec<&String> = dir_entries.iter().filter(|s| s.starts_with('.')).collect(); | ||
let unhidden_files: Vec<&String> = dir_entries.iter().filter(|s| !s.starts_with('.')).collect(); | ||
|
||
if options.all { | ||
print!(".\t..\t"); | ||
for file in hidden_files { | ||
print!("{}\t", file) | ||
} | ||
} | ||
|
||
for file in unhidden_files { | ||
print!("{}\t", file) | ||
} | ||
println!(); | ||
println!("Hola Rustacean!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
use std::process::Command; | ||
|
||
#[test] | ||
fn test_stage0() { | ||
fn test_stage_0() { | ||
let output = Command::new("./target/debug/oxidar-ls") | ||
.args(["./test_dir"]) | ||
.output() | ||
.expect("failed to execute process"); | ||
|
||
let expected = Command::new("/bin/ls") | ||
.args(["./test_dir"]) | ||
.output() | ||
.expect("failed to execute process"); | ||
|
||
println!("{}", String::from_utf8(output.stdout).unwrap()); | ||
println!("{}", String::from_utf8(expected.stdout).unwrap()); | ||
assert!(output.status.success()); | ||
assert_eq!(output.stdout, b"Hola Oxidar!\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![cfg(feature = "stage1")] | ||
|
||
use std::process::Command; | ||
|
||
#[test] | ||
fn test_stage_2() { | ||
let output = Command::new("./target/debug/oxidar-ls") | ||
.args(["-a", "./test_dir"]) | ||
.output() | ||
.expect("failed to execute process"); | ||
|
||
let expected = Command::new("/bin/ls") | ||
.args(["-a", "./test_dir"]) | ||
.output() | ||
.expect("failed to execute process"); | ||
|
||
println!("{}", String::from_utf8(output.stdout).unwrap()); | ||
println!("{}", String::from_utf8(expected.stdout).unwrap()); | ||
} |