Guest User

Untitled

a guest
Sep 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #![allow(unused_variables)]
  2.  
  3. use std::error::Error;
  4.  
  5. pub trait IxyDevice<'a> {
  6. fn new(pci_addr: &str, num_rx_queues: u16, num_tx_queues: u16) -> Result<Self, Box<Error>>
  7. where
  8. Self: Sized;
  9.  
  10. fn init(&'a mut self) -> Result<(), Box<Error>>;
  11. }
  12.  
  13. pub struct IxgbeDevice<'a> {
  14. rx_queues: Vec<&'a str>,
  15. }
  16. impl<'a> IxyDevice<'a> for IxgbeDevice<'a> {
  17. fn new(pci_addr: &str, num_rx_queues: u16, num_tx_queues: u16) -> Result<Self, Box<Error>> where
  18. Self: Sized {
  19. unimplemented!()
  20. }
  21.  
  22. fn init(&'a mut self) -> Result<(), Box<Error>> {
  23. unimplemented!()
  24. }
  25. }
  26. impl<'a> IxgbeDevice<'a> {
  27. fn new() -> IxgbeDevice<'a> {
  28. IxgbeDevice {
  29. rx_queues: Vec::new(),
  30. }
  31. }
  32. }
  33.  
  34. pub fn get_device(pci_addr: &str, rx_queues: u16, tx_queues: u16) -> Result<impl IxyDevice, Box<Error>> {
  35. let device: IxgbeDevice = IxyDevice::new(pci_addr, rx_queues, tx_queues)?;
  36. Ok(device)
  37. }
  38.  
  39. fn main() {
  40. let dev = get_device("0000:03:00.0", 1, 1).unwrap();
  41. dev.init().unwrap();
  42. }
Add Comment
Please, Sign In to add comment