[package]
name = "todo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = { version = "4.1" }
actix-rt = { version = "2.7" }
taki@DESKTOP-4VF3GEO:~/python$ python
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bin(26)
'0b11010'
>>>
[package]
name = "samplecli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "3.1.6", features = ["derive"] }
anyhow = { version = "1.0" }
thiserror = { version = "1.0" }
use thiserror::Error;
#[derive(Error, Debug)]
enum MyError {
#[error("failed to read string from {0}")]
ReadError(String),
#[error(transparent)]
ParseError(#[from] std::num::ParseIntError),
}
fn get_int_from_file() -> Result<i32, MyError> {
let path = "number.txt";
let num_str =
std::fs::read_to_string(path).map_err(|_| MyError::ReadError(path.into()))?;
num_str
.trim()
.parse::<i32>()
.map(|t| t * 2)
.map_err(MyError::from)
}
fn main() {
match get_int_from_file() {
Ok(x) => println!("{}", x),
Err(e) => println!("{:#}", e),
}
}
[package]
name = "samplecli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "3.1.6", features = ["derive"] }
anyhow = { version = "1.0.57" }
use anyhow::{Context, Result};
fn get_int_from_file() -> Result<i32> {
let path = "number.txt";
let num_str = std::fs::read_to_string(path)
.with_context(|| format!("failed to read string from {}", path))?;
num_str
.trim()
.parse::<i32>()
.map(|t| t * 2)
.context("failed to parse string")
}
fn main() {
match get_int_from_file() {
Ok(x) => println!("{}", x),
Err(e) => println!("{}", e),
}
}
package com.example.visitor;
public interface Visitor {
public void visit(ConcreteElement1 group);
public void visit(ConcreteElement2 department);
}
package com.example.visitor;
public class ConcreteVisitor implements Visitor {
public void visit(ConcreteElement1 group) {
}
public void visit(ConcreteElement2 department) {
}
}
package com.example.visitor;
public interface Element {
public void accept(Visitor visitor);
}
package com.example.visitor;
public class ConcreteElement1 implements Element {
public ConcreteElement1() {
}
public void accept(Visitor visitor) {
visitor.visit(this);
}
}
package com.example.visitor;
public class ConcreteElement2 implements Element{
public ConcreteElement2() {
}
public void accept(Visitor visitor) {
visitor.visit(this);
}
}
package com.example.visitor;
public class Main {
public static void main(String[] args) {
try {
Element element1 = new ConcreteElement1();
Element element2 = new ConcreteElement2();
element1.accept(new ConcreteVisitor());
element2.accept(new ConcreteVisitor());
} catch (Exception e) {
e.printStackTrace();
}
}
}
fn get_int_from_file() -> i32 {
let path = "number.txt";
let num_str = std::fs::read_to_string(path).expect("failed to open the file.");
let ret = num_str
.trim()
.parse::<i32>()
.expect("failed to parse string to a number.");
ret * 2
}
fn main() {
println!("{}", get_int_from_file());
}
taki@DESKTOP-4VF3GEO:~/rust/samplecli$ echo 42 > number.txt
taki@DESKTOP-4VF3GEO:~/rust/samplecli$ cargo run --bin err_panic
Compiling samplecli v0.1.0 (/home/taki/rust/samplecli)
Finished dev [unoptimized + debuginfo] target(s) in 0.38s
Running `target/debug/err_panic`
84
taki@DESKTOP-4VF3GEO:~/rust/samplecli$ echo hoge > number.txt
taki@DESKTOP-4VF3GEO:~/rust/samplecli$ cargo run --bin err_panic
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/err_panic`
thread 'main' panicked at 'failed to parse string to a number.: ParseIntError { kind: InvalidDigit }', src/bin/err_panic.rs:8:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
taki@DESKTOP-4VF3GEO:~/rust/samplecli$
package com.example.templateMethod;
public class Main {
public static void main(String[] args) {
AbstractClass process = new ConcreteClass();
process.execule();
}
}