Skip to content

Commit 200048e

Browse files
rbartlenskydanielocfb
authored andcommitted
Convert try_from/into into from/into.
These changes were suggested by clippy.
1 parent b422c8b commit 200048e

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

libbpf-rs/src/btf/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl Var<'_> {
732732
/// The kind of linkage this variable has.
733733
#[inline]
734734
pub fn linkage(&self) -> Linkage {
735-
self.ptr.linkage.try_into().unwrap_or(Linkage::Unknown)
735+
self.ptr.linkage.into()
736736
}
737737
}
738738

libbpf-rs/src/map.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,7 @@ impl MapInfo {
11751175
/// Get the map type
11761176
#[inline]
11771177
pub fn map_type(&self) -> MapType {
1178-
match MapType::try_from(self.info.type_) {
1179-
Ok(t) => t,
1180-
Err(_) => MapType::Unknown,
1181-
}
1178+
MapType::from(self.info.type_)
11821179
}
11831180

11841181
/// Get the name of this map.

libbpf-rs/src/program.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,7 @@ impl Program {
554554

555555
/// Retrieve the type of the program.
556556
pub fn prog_type(&self) -> ProgramType {
557-
match ProgramType::try_from(unsafe { libbpf_sys::bpf_program__type(self.ptr.as_ptr()) }) {
558-
Ok(ty) => ty,
559-
Err(_) => ProgramType::Unknown,
560-
}
557+
ProgramType::from(unsafe { libbpf_sys::bpf_program__type(self.ptr.as_ptr()) })
561558
}
562559

563560
/// Returns program fd by id

libbpf-rs/src/query.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ impl ProgramInfo {
292292

293293
// SANITY: `libbpf` should guarantee NUL termination.
294294
let name = util::c_char_slice_to_cstr(&item.name).unwrap();
295-
let ty = match ProgramType::try_from(item.type_) {
296-
Ok(ty) => ty,
297-
Err(_) => ProgramType::Unknown,
298-
};
295+
let ty = ProgramType::from(item.type_);
299296

300297
if opts.include_xlated_prog_insns {
301298
xlated_prog_insns.resize(item.xlated_prog_len as usize, 0u8);
@@ -464,10 +461,7 @@ impl MapInfo {
464461
fn from_uapi(_fd: BorrowedFd<'_>, s: libbpf_sys::bpf_map_info) -> Option<Self> {
465462
// SANITY: `libbpf` should guarantee NUL termination.
466463
let name = util::c_char_slice_to_cstr(&s.name).unwrap();
467-
let ty = match MapType::try_from(s.type_) {
468-
Ok(ty) => ty,
469-
Err(_) => MapType::Unknown,
470-
};
464+
let ty = MapType::from(s.type_);
471465

472466
Some(Self {
473467
name: name.to_owned(),
@@ -673,25 +667,22 @@ impl LinkInfo {
673667
})
674668
}
675669
libbpf_sys::BPF_LINK_TYPE_TRACING => LinkTypeInfo::Tracing(TracingLinkInfo {
676-
attach_type: ProgramAttachType::try_from(unsafe {
670+
attach_type: ProgramAttachType::from(unsafe {
677671
s.__bindgen_anon_1.tracing.attach_type
678-
})
679-
.unwrap_or(ProgramAttachType::Unknown),
672+
}),
680673
}),
681674
libbpf_sys::BPF_LINK_TYPE_CGROUP => LinkTypeInfo::Cgroup(CgroupLinkInfo {
682675
cgroup_id: unsafe { s.__bindgen_anon_1.cgroup.cgroup_id },
683-
attach_type: ProgramAttachType::try_from(unsafe {
676+
attach_type: ProgramAttachType::from(unsafe {
684677
s.__bindgen_anon_1.cgroup.attach_type
685-
})
686-
.unwrap_or(ProgramAttachType::Unknown),
678+
}),
687679
}),
688680
libbpf_sys::BPF_LINK_TYPE_ITER => LinkTypeInfo::Iter,
689681
libbpf_sys::BPF_LINK_TYPE_NETNS => LinkTypeInfo::NetNs(NetNsLinkInfo {
690682
ino: unsafe { s.__bindgen_anon_1.netns.netns_ino },
691-
attach_type: ProgramAttachType::try_from(unsafe {
683+
attach_type: ProgramAttachType::from(unsafe {
692684
s.__bindgen_anon_1.netns.attach_type
693-
})
694-
.unwrap_or(ProgramAttachType::Unknown),
685+
}),
695686
}),
696687
_ => LinkTypeInfo::Unknown,
697688
};

0 commit comments

Comments
 (0)