Skip to main content

Perl

Struct Perl 

Source
pub struct Perl { /* private fields */ }
Expand description

A live Perl interpreter. Allocated by perl_alloc and torn down by perl_destruct on drop.

The my_perl field is NonNull<PerlInterpreter> so that the “interpreter is never null” invariant is encoded in the type. FFI calls extract a raw pointer via Perl::as_ptr — that’s the boundary where Rust’s safe-typed world meets the C ABI.

Implementations§

Source§

impl Perl

Source

pub fn new() -> Self

Allocate and construct a fresh interpreter. Panics on allocation failure (typically OOM, very rare).

Examples found in repository?
examples/scan_ops.rs (line 30)
29fn main() {
30    let mut perl = Perl::new();
31    perl.parse_env_args(env::args(), env::vars());
32
33    // Standard C-style THX setup at the top of the function:
34    let my_perl = perl.as_ptr();
35    scan_ops(PL_main_start!(my_perl));
36}
Source

pub fn as_ptr(&self) -> *mut PerlInterpreter

Raw pointer for FFI. The conventional name is my_perl at the call site — see docs/plan/README.md §3.8 for naming rules.

Examples found in repository?
examples/scan_ops.rs (line 34)
29fn main() {
30    let mut perl = Perl::new();
31    perl.parse_env_args(env::args(), env::vars());
32
33    // Standard C-style THX setup at the top of the function:
34    let my_perl = perl.as_ptr();
35    scan_ops(PL_main_start!(my_perl));
36}
Source

pub unsafe fn from_raw_unchecked(p: *mut PerlInterpreter) -> Self

Wrap a raw *mut PerlInterpreter as a borrowed Perl.

§Safety
  • p must point to a live, valid interpreter.
  • The returned Perl MUST NOT be dropped: its Drop runs perl_destruct, tearing down an interpreter this constructor does not own. The intended usage is to wrap in core::mem::ManuallyDrop immediately. The #[xs_sub] proc-macro does this when a body declares a my_perl: &Perl first parameter.
Source

pub fn parse<S: AsRef<str>>(&mut self, args: &[S], envp: &[S]) -> i32

perl_parse with an explicit args / envp slice.

Source

pub fn parse_env_args(&mut self, args: Args, envp: Vars) -> i32

perl_parse driven from std::env::args() / vars().

Examples found in repository?
examples/scan_ops.rs (line 31)
29fn main() {
30    let mut perl = Perl::new();
31    perl.parse_env_args(env::args(), env::vars());
32
33    // Standard C-style THX setup at the top of the function:
34    let my_perl = perl.as_ptr();
35    scan_ops(PL_main_start!(my_perl));
36}

Trait Implementations§

Source§

impl Default for Perl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Perl

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Send for Perl

§

impl !Sync for Perl

§

impl Freeze for Perl

§

impl RefUnwindSafe for Perl

§

impl Unpin for Perl

§

impl UnsafeUnpin for Perl

§

impl UnwindSafe for Perl

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.