Skip to content

PWRS Wiki

PWRS logo

Rust bindings for PowerShell binary modules, in the spirit of PyO3 . A cmdlet is a Rust struct, and its parameters are that struct’s fields, coerced, validated and completed by PowerShell’s own binder before your code runs. cargo pwrs build produces a module folder that imports into PowerShell 7 from 7.4 on and Windows PowerShell 5.1 with no .NET SDK on the machine.

Quick links

  • New here? Getting Started - from cargo pwrs new to Import-Module.
  • Want to see everything at once? Hello Tour - the examples/hello module, cmdlet by cmdlet, with the Pester tests that pin each behavior.
  • Choosing a type for a parameter or an output? Conversions Reference .
  • Writing to the pipeline, the streams, or session state? Pipeline Reference .
  • Need to know what crosses the boundary and how? The Bridge and ABI Reference .
  • Need numbers? Benchmarks - what was measured, on which box, with which controls.

What PWRS is

PyO3PWRS
#[pymodule] and PyInit_pwrs::export_module! and the generated module folder
#[pyfunction]#[cmdlet] on a struct implementing Cmdlet
function arguments#[param] fields, bound by the engine’s own binder
return valuethe output stream, ps.write(value)
a Python exceptionPsError with an ErrorCategory, an id, and a terminating flag
#[pyclass]#[psclass] in copied, proxy, or psobject mode; #[psenum] for enums
PyObjectPsObject, an owned GCHandle
Python<'py>Pipeline<'ps>, the !Send pipeline-thread token
abi3the append-only host vtable
maturincargo pwrs
embeddingpwrs-host

See PWRS and PyO3 for the full comparison, including what PWRS has that PyO3 does not (providers, completers, dynamic parameters, two hosts from one build) and what PyO3 has that PWRS does not.

What PWRS is not

  • Not a way to run Rust inside PowerShell script. The Rust code is compiled ahead of time into a native library that a generated binary module loads. There is no REPL and no scripting bridge.
  • Not a C# replacement. The shell is generated C#, and a module may add hand-written C# cmdlets beside the Rust ones (Hybrid C# ).
  • Not a scheduler. Off-thread work uses std threads and channels through stream_from_thread; bring your own thread pool.

Wiki contents

Tutorials

  • Getting Started - scaffold, build, test, import.
  • Hello Tour - every cmdlet in examples/hello, what it exercises, and its test.

How-to

Explanation

  • Why PWRS - the problem PyO3 does not have and the four ways it could have been solved.
  • The Bridge - the generated shell, the vtable, the exports, and the two rules at the boundary.
  • The Call Path - what one invocation costs and why.
  • Two Hosts - PowerShell 7 from 7.4 on and Windows PowerShell 5.1 from one build.
  • PWRS and PyO3 .

Reference

License

MIT - see LICENSE on the repository.