先用起来再说
use std::io::prelude::*;
use std::os::unix::net::UnixStream;fn main() {let mut stream: UnixStream;let mut buffer = vec![0u8; 4096];match UnixStream::connect("/tmp/hello.world.serv") {Ok(handle) => {stream = handle;match stream.write_all("cmd=read".as_bytes()) {Ok(_) => {println!("send to unix domain socket successfully");match stream.read(&mut buffer) {Ok(_) => {println!("read uds buffer okay");//This step change utf8 code for recv bufferprintln!("Content:{:?}", String::from_utf8(buffer));}Err(error) => println!("read uds buffer errors {:?}", error),}}Err(error) => println!("{:?}", error),}}Err(error) => {println!("{:?}", error)}};
}
编写rust 不是看编译时报错,而是更重要的是关注,lsp 返回的语法错误,只要又错误,大概率是不会编译成功的
rust使用了C的连接器,但是丰富了C 的库,从项目中的小组件开始迭代
除非,linux 驱动有crates 否则不建议使用 unsafe 去调用
use std::io::prelude::*;
use std::os::unix::net::UnixStream;#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {let mut stream: UnixStream;let mut buffer = vec![0u8; 4096];let mut cmd = ["cmd=para_list", "cmd=read"];let mut cmdVec = cmd.to_vec();for it in cmdVec.iter_mut() {if *it == "cmd=para_list" {*it = "cmd=para_all_list";} else if it == &"cmd=read" {*it = "cmd=read_all_cache";}}println!("new static str vec: {:?}", cmdVec);match UnixStream::connect("/tmp/uds.network.serv") {Ok(handle) => {stream = handle;match stream.write_all("cmd=read".as_bytes()) {Ok(_) => {println!("send to unix domain socket successfully");match stream.read(&mut buffer) {Ok(_) => {println!("read uds buffer okay");//This step change utf8 code for recv bufferprintln!("Content:{:?}", String::from_utf8(buffer));}Err(error) => println!("read uds buffer errors {:?}", error),}}Err(error) => println!("{:?}", error),}}Err(error) => {println!("{:?}", error)}};
}
和python 一样的可用性
也有引用和解引用,但是用起来就比较麻烦
也有指针和原始指针
不考虑复杂的过程宏和装饰器的作用大差不差