-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
I started with trying to add support for connecting to containers, but I've found way too many issues just in this code I was going to put into an /examples/ file:
#![warn(rust_2018_idioms)]
use clap::Parser;
use utf8_cstr::Utf8CStr;
#[derive(Parser)]
struct Args {
#[args(short = 'M', long)]
machine: String,
service: String,
}
#[cfg(feature = "bus")]
fn main() -> anyhow::Result<()> {
let Args { machine, service } = Args::parse();
// the function I was going to add
let mut bus = systemd::bus::Bus::open_system_machine(&machine)?;
let mut method_call = bus.new_method_call(
// ⚠️ Null-terminated strings? I don't want to deal with that, all my code uses &str.
// ⚠️ `?` couldn't convert the error: `str: std::error::Error` is not satisfied
// omg! the errors are strings...
systemd::bus::BusName::from_bytes(b"org.freedesktop.systemd1\0")?,
systemd::bus::ObjectPath::from_bytes(b"/org/freedesktop/systemd1\0")?,
systemd::bus::InterfaceName::from_bytes(b"org.freedesktop.systemd1.Manager\0")?,
systemd::bus::MemberName::from_bytes(b"StartUnit\0")?,
)?;
// args
method_call.append(Utf8CStr::from_bytes(b"foo.service\0")?)?;
method_call.append(Utf8CStr::from_bytes(b"fail\0")?)?;
let res = method_call.call(0)?;
eprintln!("done, result={:?}", *res);
Ok(())
}
#[cfg(not(feature = "bus"))]
fn main() {
println!("bus disabled");
}I genuinely don't understand what the point of this crate is because it solves the unsafe problem, but then it doesn't go all the way! This is what I was expecting:
let bus = Bus::open_system_machine(&machine)?;
bus.start_unit(&unit)?;Okay, maybe not that simplified, but this is just really not acceptable. I'm basically 50/50 deciding if I just learn unsafe Rust, or rewrite all the pain points of this crate in a fork.
I'm not sure what kind of response I'm expecting because on the one hand, I need a library that fits my needs, but on the other hand I may not understand the point of this crate.
Metadata
Metadata
Assignees
Labels
No labels