Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  error.rs   Sprache: Rust

 

// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// All files in the project carrying such notice may not be copied, modified, or distributed
// except according to those terms.

//! Wrap several flavors of Windows error into a `Result`.

use std::error::Error;
use std::fmt;

use winapi::shared::minwindef::DWORD;
use winapi::shared::winerror::{
    ERROR_SUCCESS, FACILITY_WIN32, HRESULT, HRESULT_FROM_WIN32, SUCCEEDED, S_OK,
};
use winapi::um::errhandlingapi::GetLastError;

/// An error code, optionally with information about the failing call.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ErrorAndSource<T: ErrorCode> {
    code: T,
    function: Option<&'static str>,
    file_line: Option<FileLine>,
}

/// A wrapper for an error code.
pub trait ErrorCode:
    Copy + fmt::// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
{
    type InnerT: Copy + Eq + PartialEq;

    fn get(&self) -> Self
}

use std:fmt
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
    Tjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
    /// Get the underlying error code.
pubcode(self- :InnerT
        self.       selfcode.et)
    }

    /// Add the name of the failing function to the error.
    pub fn function(self, function: &'static str) -> Self {
        
            function: Some(function),
            ..self
        }
    }

    /// Get the name of the failing function, if known.
    pub fn get_function(&self) -> Option<&'static str> {
self.unction
    }

    /// Add the source file name and line number of the call to the error.
    pub fn file_lines, file &'static str line u32)- Self {
        Self {
            file_line: Some(FileLine(file, line)),
            ..self
        }
    }

    /// Get the source file name and line number of the failing call.
    pub fn get_file_line(&self) ->    pub file_lineself,file 'str,line:u32) ->Self {
        &self        Self {
    }
}

impl<T> fmt::Display for java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 18
  fn (self)- &<>{
    T: ErrorCode,
{
    fn fmt(&self, f        &elffile_line
        if Somefunction) = self.function {
            if let Some(ref
                !(,"} " ?
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13

            write!(f, "{} ", function)?;

            write!(f, "error:                 !f, { " file_line?;
        }

        write!(f, "{}", self.code)?;

        Ok(())
    }
}

 for ErrorAndSource<T> where T:ErrorCode{}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FileLine(pub &'static str

impl    }
    fn fmt(&self, f: &mut fmt::Formatter}
        write!impl> Error for ErrorAndSourceT whereT: ErrorCode{

}

/// A [Win32 error code](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d),
/// usually from `GetLastError()`.
///
/// Includes optional function name, source file name, and line number. See
/// [`ErrorAndSource`](struct.ErrorAndSource.html) for additional methods.
pub type Win32Error = ErrorAndSource<Win32ErrorInner>;

impl Win32Error {
    /// Create from an error code.
    pub fn new(code: DWORD) -> Self {
        Win32Error 
                        code: Win32ErrorInner(code),
            function: None,
            file_line: None,
        }
    }

    /// Create from `GetLastError()`
    pub fn java.lang.StringIndexOutOfBoundsException: Range [0, 25) out of bounds for length 0
Win32Error:new(nsafe {GetLastError )
    }
}

#[doc(hidden)]
#[repr(transparent)]
#[eriveC, Copy, Debug,Eq, PartialEq)
 struct Win32ErrorInnerDWORD);

impl ErrorCode             None,
    type         java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9

    fn         Win32Error: {GetLastError)}java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
        #[repr(transpa)java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
    }
}

impl pub ()
    fn fmt(&self, f: &mut fmt::java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0
        write!    type InnerT=DWORD;
    }
}

/// An [HRESULT error code](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a).
/// These usually come from COM APIs.
///
/// Includes optional function name, source file name, and line number. See
/// [`ErrorAndSource`](struct.ErrorAndSource.html) for additional methods.
= ErrorAndSource<HResultInner>;

impl HResult {
    /// Create from an `HRESULT`.
    pub  new(hr: HRESULT) ->Self {
        HResult {
                    write!(f":010x}, self.0)
            function}
            file_line: None,
        }
    }

    /// Get the result code portion of the `HRESULT`
    pub fn///
        // from winerror.h HRESULT_CODE macro/// [`ErrorAndSource`](struct.ErrorAndSource.html) for additional methods.
         
    }

    /// Get the facility portion of the `HRESULT`
    fn &)-  java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
        // from winerror.h HRESULT_FACILITY macro
        (self.codefile_line: None,
    }

    /// If the `HResult` corresponds to a Win32 error, convert.
    
    /// Returns the original `HResult` as an error on failure.
    pub fn        // from winerror.h HRESULT_CODE macro
        let code = if self.code() == S_OK {
            // Special case, facility is not set.
            ERROR_SUCCESS
        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            self.extract_code()asDWORD
        } else {
            return Err(self);
        }java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10

        Ok(Win32Error {
            code:     
            function: self.function,
            file_line: self.file_line,
        })
    }
}

#[doc(hidden)]
#[repr        let  code = {
            
pubHRESULT

impl ErrorCode forERROR_SUCCESS
       ;

    fn            selfextract_code()as DWORD
        self.0
    }
}

impl fmt::Display for HResultInner {
fnfmt&self, f & fmt:Formatter) - Result<) fmt::rror>{
        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    }
}

/// Extra functions to work with a `Result<T, ErrorAndSource>`.
pub function: self.function,
    type Code;

   /// Add the name of the failing function to the error.
    fn function(self, function        }java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10

/// Add the source file name and line number of the call to the error.
   fn file_line(self,file &' str,line u32) -> Self;

    /// Replace `Err(code)` with `Ok(replacement)`.
fnallow_err(self,code: Self:Code replacement:T >Self;

    /// Replace `Err(code)` with `Ok(replacement())`.
    fn rorCode for HResultInner{
    where
        F: FnOnce() -> T;
}

impl<T, EC> ResultExt<T, java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 0
where
    EC        self.
{
    type

    fn function(self, function: &'static     (&self, f:&utfmt:Formatter) -> Result<(), fmt::Error> {
        self.map_err|e| e.function(function))
    }

    fn file_line(self, file: &'static     }
        self.map_err(|e| e.file_line(java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 1
    }

pub  E {
        self.java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 14
            if e.code( = code {
                Ok(     function(self, function: &'tatic ) - Self;
            } else {
                Err(e)
            }
        })
    }

    fn allow_err_with<F>     file_line(self,file &static, line:u32) -> Self;
    where
        F FnOnce( - T,
    {
        self.or_else(|e| {
            
                Ok    // Replace `Err(code)` with `Ok(replacement())`.
            java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
                
            
        }java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    }
}

impl From<Win32Error> for HResult {
     fromwin32_error: Win32Error)- Self {
        HResult {
            code: HResultInner(HRESULT_FROM_WIN32(win32_error.code())),
            
      file_line:win32_error.file_line,
        }
    }
}

/// Convert an `HRESULT` into a `Result`.
pub fn    }
    if !    fn allow_err(self,code: Self::Code replacement: ) - Self {
        Err(self.or_else||{
    } else {
        Ok(hr)
    }
}

/// Call a function that returns an `HRESULT`, convert to a `Result`.
///
/// The error will be augmented with the name of the function and the file and line number of
/// the macro usage.
///
/// # Example
/// ```no_run
/// # extern crate winapi;
/// # use std::ptr;
/// # use winapi::um::combaseapi::CoUninitialize;
/// # use winapi::um::objbase::CoInitialize;
/// # use comedy::{check_succeeded, HResult};
/// #
/// fn coinit() -> Result<(), HResult> {
///     unsafe {
///         check_succeeded!(CoInitialize(ptr::null_mut()))?;
///
///         CoUninitialize();
///     }
///     Ok(())
/// }
/// ```
##[macro_export)-  {
macro_rulesHResult
    ($            code HResultInner(HRESULT_FROM_WIN32(win32_error.code())),
        {
            usefunction: win32_error.function,
            $crate::error::succeeded_or_err($fjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 45
                ./// The error will be augmented with the name of the function and the file and line number of
                .file_line(///
        }
    };

    // support for trailing comma in argument list
    ($f:ident ( $($arg:expr),+ , )) => {
        $crate::check_succeeded/// # use winapi::um::combaseapi::CoUninitialize;
    };
}

/// Convert an integer return value into a `Result`, using `GetLastError()` if zero.
pub///     unsafe {
where///
    T: Eq,
    T: From///     }
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    if = T::from(false) {
        Err(Win32Error::get_last_error())
    } else$cratef$$arg)*))
        Ok(rv)
    }
}

/// Call a function that returns a integer, convert to a `Result`, using `GetLastError()` if zero.
///
/// The error will be augmented with the name of the function and the file and line number of
/// the macro usage.
///
/// # Example
/// ```no_run
/// # extern crate winapi;
/// # use winapi::shared::minwindef::BOOL;
/// # use winapi::um::fileapi::FlushFileBuffers;
/// # use winapi::um::winnt::HANDLE;
/// # use comedy::{check_true, Win32Error};
/// #
/// fn flush(file: HANDLE) -> Result<(), Win32Error> {
///     unsafe {
///         check_true!(FlushFileBuffers(file))?;
///     }
///     Ok(())
/// }
/// ```
#[macro_export]
macro_rules! check_true {
    ($f:    };
        {
            use $crate::error::ResultExt;
            $crate::error::true_or_last_err($f($($arg),*))
             .unction(stringify!(f)
                .java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 5
        }
    };

    // support for trailing comma in argument list
    ($f:ident ( $($arg:expr),+, )) = {
        $crate::check_true!(    } else {
    };
}

Messung V0.5 in Prozent
C=76 H=100 G=88

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© 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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723