mirror of
https://git.proxmox.com/git/perlmod
synced 2025-10-04 19:55:43 +00: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.
|
/// Bless a reference into a package. The `Value` must be a reference.
|
||||||
pub fn bless(&self, package: &str) -> Result<Value, Error> {
|
pub fn bless(&self, package: &str) -> Result<Value, Error> {
|
||||||
let pkgsv = Scalar::new_string(package);
|
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) };
|
let stash = unsafe { ffi::RSPL_gv_stashsv(pkgsv.sv(), 0) };
|
||||||
if stash.is_null() {
|
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) };
|
let value = unsafe { ffi::RSPL_sv_bless(self.sv(), stash) };
|
||||||
if value.is_null() {
|
if value.is_null() {
|
||||||
return Err(Error(format!(
|
return Err(Error(format!(
|
||||||
"failed to bless value into package {:?}",
|
"failed to bless value into package {:?}",
|
||||||
package
|
pkgsv.pv_utf8()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user