rust-vmm / vmm-sys-util

Helpers and utilities used by multiple rust-vmm components and VMMs
BSD 3-Clause "New" or "Revised" License
79 stars 64 forks source link

Implement trait std::error::Error for vmm_sys_util::errno::Error #67

Closed MrXinWang closed 4 years ago

MrXinWang commented 4 years ago

Referencing issue #58 , a basic implementation is proposed in this PR.

  1. Implemented method source from std::error::Error for the custom error type vmm_sys_util::errno::Error.

  2. Added unit test code for above implementation

Personally I think: Since the custom error type pub struct Error(i32) is just a wrapper of standard error, therefore there is no underlying error, hence we should always return None in the source method. Please do correct me if I am wrong. Thanks very much!

Signed-off-by: Henry Wang <henry.wang@arm.com>

MrXinWang commented 4 years ago

@jiangliu Could you please take another look? Thanks!

alxiord commented 4 years ago

Hey @MrXinWang, I think you should squash the commits, as the 2nd change is minor. Good to merge after that :+1:

MrXinWang commented 4 years ago

Hi @aghecenco ! Already squashed these two commits into a single one :) Thanks

haraldh commented 4 years ago

impl StdError for Error {} would have sufficed, I think

haraldh commented 4 years ago

or even shorter and more clear to the reader without the use ... as StdError:

impl std::error::Error for Error {}
andreeaflorescu commented 4 years ago

@haraldh since this commit is already merged, do you want to submit a fix in a PR?