Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/alsa/src/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  card.rs

  Sprache: Rust
 

//! Sound card enumeration
use libc::{c_int, c_char};
use super::error::*;
use crate::alsa;
use std::ffi::CStr;

/// An ALSA sound card, uniquely identified by its index.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Card(c_int);

/// Iterate over existing sound cards.
pub struct Iter(c_int);

impl Iter {
    pub fn new() -> Iter { Iter(-1) }
}

impl Iterator for Iter {
    type Item = Result<Card>;

    fn next(&mut self) -> Option<Result<Card>> {
        match acheck!(snd_card_next(&mut self.0)) {
            Ok(_) if self.0 == -1 => None,
            Ok(_) => Some(Ok(Card(self.0))),
            Err(e) => Some(Err(e)),
        }
    }
}

impl Card {
    pub fn new(index: c_int) -> Card { Card(index) }
    pub fn from_str(s: &CStr) -> Result<Card> {
        acheck!(snd_card_get_index(s.as_ptr())).map(Card)
    }
    pub fn get_name(&self) -> Result<String> {
        let mut c: *mut c_char = ::std::ptr::null_mut();
        acheck!(snd_card_get_name(self.0, &mut c))
            .and_then(|_| from_alloc("snd_card_get_name", c)) 
    }
    pub fn get_longname(&self) -> Result<String> {
        let mut c: *mut c_char = ::std::ptr::null_mut();
        acheck!(snd_card_get_longname(self.0, &mut c))
            .and_then(|_| from_alloc("snd_card_get_longname", c)) 
    }

    pub fn get_index(&self) -> c_int { self.0 }
}

#[test]
fn print_cards() {
    for a in Iter::new().map(|a| a.unwrap()) {
        println!("Card #{}: {} ({})", a.get_index(), a.get_name().unwrap(), a.get_longname().unwrap())
    }
}

Messung V0.5 in Prozent
C=66 H=96 G=82

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.