aya: impl From<obj::InvalidMapTypeError> for MapTypeError

reviewable/pr629/r77
Andrew Werner 1 year ago committed by Tamir Duberstein
parent cb455febbb
commit b73c0a46f5
No known key found for this signature in database

@ -710,12 +710,8 @@ impl<'a> BpfLoader<'a> {
} }
fn parse_map(data: (String, MapData)) -> Result<(String, Map), BpfError> { fn parse_map(data: (String, MapData)) -> Result<(String, Map), BpfError> {
let name = data.0; let (name, map) = data;
let map = data.1; let map_type = bpf_map_type::try_from(map.obj().map_type()).map_err(MapError::from)?;
let map_type =
bpf_map_type::try_from(map.obj().map_type()).map_err(|e| MapError::InvalidMapType {
map_type: e.map_type,
})?;
let map = match map_type { let map = match map_type {
BPF_MAP_TYPE_ARRAY => Map::Array(map), BPF_MAP_TYPE_ARRAY => Map::Array(map),
BPF_MAP_TYPE_PERCPU_ARRAY => Map::PerCpuArray(map), BPF_MAP_TYPE_PERCPU_ARRAY => Map::PerCpuArray(map),

@ -61,6 +61,7 @@ use std::{
use libc::{getrlimit, rlim_t, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY}; use libc::{getrlimit, rlim_t, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY};
use log::warn; use log::warn;
use obj::maps::InvalidMapTypeError;
use thiserror::Error; use thiserror::Error;
use crate::{ 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<InvalidMapTypeError> for MapError {
fn from(e: InvalidMapTypeError) -> Self {
let InvalidMapTypeError { map_type } = e;
Self::InvalidMapType { map_type }
}
}
/// A map file descriptor. /// A map file descriptor.
#[derive(Debug)] #[derive(Debug)]
pub struct MapFd(OwnedFd); pub struct MapFd(OwnedFd);

@ -1251,6 +1251,8 @@ impl core::convert::From<aya::maps::MapError> for aya::maps::xdp::XdpMapError
pub fn aya::maps::xdp::XdpMapError::from(source: aya::maps::MapError) -> Self pub fn aya::maps::xdp::XdpMapError::from(source: aya::maps::MapError) -> Self
impl core::convert::From<aya::maps::MapError> for aya::programs::ProgramError impl core::convert::From<aya::maps::MapError> for aya::programs::ProgramError
pub fn aya::programs::ProgramError::from(source: aya::maps::MapError) -> Self pub fn aya::programs::ProgramError::from(source: aya::maps::MapError) -> Self
impl core::convert::From<aya_obj::maps::InvalidMapTypeError> for aya::maps::MapError
pub fn aya::maps::MapError::from(e: aya_obj::maps::InvalidMapTypeError) -> Self
impl core::error::Error for aya::maps::MapError impl core::error::Error for aya::maps::MapError
pub fn aya::maps::MapError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)> pub fn aya::maps::MapError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)>
impl core::fmt::Display for aya::maps::MapError impl core::fmt::Display for aya::maps::MapError

Loading…
Cancel
Save