mirror of
git://git.proxmox.com/git/perlmod.git
synced 2025-03-13 04:58:16 +03:00
Value: add bless_sv method for convenience
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
e62be4a750
commit
0eebb7e1d9
@ -68,16 +68,23 @@ impl Value {
|
||||
/// Bless a reference into a package. The `Value` must be a reference.
|
||||
pub fn bless(&self, package: &str) -> Result<Value, Error> {
|
||||
let pkgsv = Scalar::new_string(package);
|
||||
self.bless_sv(&pkgsv)
|
||||
}
|
||||
|
||||
pub fn bless_sv(&self, pkgsv: &ScalarRef) -> Result<Value, Error> {
|
||||
let stash = unsafe { ffi::RSPL_gv_stashsv(pkgsv.sv(), 0) };
|
||||
if stash.is_null() {
|
||||
return Err(Error(format!("failed to find package {:?}", package)));
|
||||
return Err(Error(format!(
|
||||
"failed to find package {:?}",
|
||||
pkgsv.pv_utf8()
|
||||
)));
|
||||
}
|
||||
|
||||
let value = unsafe { ffi::RSPL_sv_bless(self.sv(), stash) };
|
||||
if value.is_null() {
|
||||
return Err(Error(format!(
|
||||
"failed to bless value into package {:?}",
|
||||
package
|
||||
pkgsv.pv_utf8()
|
||||
)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user