diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index eed006d4..0af51faf 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -709,12 +709,8 @@ impl<'a> BpfLoader<'a> { } fn parse_map(data: (String, MapData)) -> Result<(String, Map), BpfError> { - let name = data.0; - let map = data.1; - let map_type = - bpf_map_type::try_from(map.obj.map_type()).map_err(|e| MapError::InvalidMapType { - map_type: e.map_type, - })?; + let (name, map) = data; + let map_type = bpf_map_type::try_from(map.obj.map_type()).map_err(MapError::from)?; let map = match map_type { BPF_MAP_TYPE_ARRAY => Map::Array(map), BPF_MAP_TYPE_PERCPU_ARRAY => Map::PerCpuArray(map), diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 5dce668e..23123007 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -51,6 +51,7 @@ use std::{ use crate::util::KernelVersion; use libc::{getrlimit, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY}; use log::warn; +use obj::maps::InvalidMapTypeError; use thiserror::Error; use crate::{ @@ -193,6 +194,16 @@ pub enum MapError { }, } +// Note that this is not just derived using #[from] because InvalidMapTypeError cannot implement +// Error due the the fact that aya-obj is nostd and error_in_core is not stabilized +// (https://github.com/rust-lang/rust/issues/103765). +impl From for MapError { + fn from(e: InvalidMapTypeError) -> Self { + let InvalidMapTypeError { map_type } = e; + MapError::InvalidMapType { map_type } + } +} + /// A map file descriptor. pub struct MapFd(RawFd); diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index a32ec8a5..a1b749ec 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -1005,6 +1005,8 @@ impl core::convert::From for aya::BpfError pub fn aya::BpfError::from(source: aya::maps::MapError) -> Self impl core::convert::From for aya::programs::ProgramError pub fn aya::programs::ProgramError::from(source: aya::maps::MapError) -> Self +impl core::convert::From for aya::maps::MapError +pub fn aya::maps::MapError::from(e: aya_obj::maps::InvalidMapTypeError) -> Self impl core::error::Error for aya::maps::MapError pub fn aya::maps::MapError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)> impl core::fmt::Display for aya::maps::MapError