diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 57162163..540da073 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -710,12 +710,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 45d5a921..ee6acb82 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -61,6 +61,7 @@ use std::{ use libc::{getrlimit, rlim_t, 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 no_std 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; + Self::InvalidMapType { map_type } + } +} + /// A map file descriptor. #[derive(Debug)] pub struct MapFd(OwnedFd); diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index fb3f5b58..6891b279 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -1251,6 +1251,8 @@ impl core::convert::From for aya::maps::xdp::XdpMapError pub fn aya::maps::xdp::XdpMapError::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