matklad / xshell

Apache License 2.0
675 stars 28 forks source link

DRAFT: Simplify the API and inner implementation #85

Open elichai opened 5 months ago

elichai commented 5 months ago

As discussed in #84 this refactors the API to replace RAII based pushd/popd into subtree like structure where you get a subshell by cloning/push_dir.

This is a draft for an initial implementation, I'm also playing with the idea of having our own trait AsOsStr with some kind of private enum like:

enum OsStr {
    Shared(Arc<OsStr>),
    Static(&'static str),
}

that way things like sh.env("foo", "bar") will not do any heap alloctation aside for pushing into the hashmap

elichai commented 5 months ago

With this things like #83 become much easier

elichai commented 5 months ago

@matklad Thank you for the thorough feedback and review!

This should not be a performance bottleneck. You use xshell to read files and/or run externall processes. The relevant systcalls should dwarf any nanoseconds we spend on allocation and memcpying

Yeah I was going back and forth a lot trying to find a "good" common ground between cloning everything and having a simple API and library :)

elichai commented 3 months ago

Hi, I'm back from a long vacation :) pushed a small update, if you're Ok with the direction I can soon find time to work on updating tests and examples to better show the intended use-cases