fn chto_to(&self) -> impl StringAnalyzer;fn lexing<T>(&self) -> T where T: StringAnalyzer;pub trait NewTrait {
type AssociatedType: ExistingTrait;
fn function() -> Self::AssociatedType;
}
rustup update stable
mkdir cross_comp
cd cross_comp
cargo init --bin
cargo target add aarch64-unknown-linux-gnu
sudo apt install g++-aarch64-linux-gnu libc6-dev-arm64-cross
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
cargo build --target=aarch64-unknown-linux-gnurustup update stable
mkdir cross_comp
cd cross_comp
cargo init --bin
cargo target add aarch64-unknown-linux-gnu
&'static str (собственно то, что ты в panic и засунул)Err(err) => {
println!("{}", err.is::<&'static str>());
let value = err.downcast::<&'static str>().unwrap();
println!("{}", value); // Выводит строку failed to spawn
}
Или возвращатьBoxплохая идея, а нужно засовывать другие ошибки внутрь своего кастомного типа?
fn read() -> Result<(), io::Err> {
//let vec: Vec<u8> = !vec[2, 5, 8, 10, 15, 16];
let pos1 = self.responce.iter().position(|&el| el == 8).ok_or_else(||io::Err::new("understading message"))?;
let pos2 = self.responce.iter().position(|&el| el == 15).ok_or_else(||io::Err::new("understading message"))?;
let pos3 = self.responce.iter().position(|&el| el == 12).ok_or_else(||io::Err::new("understading message"))?;
return Ok(());
}
self.on_event_closure
.entry(event)
.or_insert_with(Vec::new)
.and_modify(move |vec| vec.push(f));
let a_ : &mut[u8] = &mut a;
Во-первых, что значит последняя строчка? как это расшифровать?
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
pub struct Animal {
pub name: String,
pub age: i32,
pub strength: i32,
}
pub struct Person {
pub name: String,
pub age: i32,
pub strength: i32,
}
// Выделяем новый трейт, который позволяет получить силу
trait Strength {
fn strength(&self) -> i32;
}
trait BaseTrait {
fn init(&self);
// В старом трейте принимаем target по ссылке и ограничиваем, что принимаем только такой target, который реализует trait Strength
fn stronger_than<T>(&self, target: &T) -> bool
where
T: Strength;
}
impl Strength for Person {
fn strength(&self) -> i32 {
self.strength
}
}
impl Strength for Animal {
fn strength(&self) -> i32 {
self.strength
}
}
impl BaseTrait for Person {
fn init(&self) {
println!("Hello, im Person: {}", self.name);
}
fn stronger_than<T>(&self, enemy: &T) -> bool
where
T: Strength,
{
self.strength > enemy.strength() // вызываем метод, вместо обращения к полю
}
}
impl BaseTrait for Animal {
fn init(&self) {
println!("Hello, im Animal: {}", self.name);
}
fn stronger_than<T>(&self, enemy: &T) -> bool
where
T: Strength,
{
self.strength > enemy.strength()
}
}
fn main() {
let person = Person {
name: String::from("John"),
age: 25,
strength: 12,
};
let animal = Animal {
name: String::from("Elephant"),
age: 5,
strength: 360,
};
person.init();
animal.init();
if person.stronger_than(&animal) {
println!("Person is stronger than animal");
}
if animal.stronger_than(&person) {
println!("Animal is stronger than person")
}
}