pub fn default_target(
    platform: &Platform,
    target: Option<&str>,
    service: &str,
    username: &str,
) -> PlatformCredential {
    const VERSION: &str = env!("CARGO_PKG_VERSION");
    let custom = if target.is_none() {
        "entry"
    } else {
        "custom entry"
    };
    let metadata = format!(
        "keyring-rs v{} {} for service '{}', user '{}'",
        VERSION, custom, service, username
    );
    match platform {
        Platform::Linux => PlatformCredential::Linux(LinuxCredential {
            collection: target.unwrap_or("default").to_string(),
            attributes: HashMap::from([
                ("service".to_string(), service.to_string()),
                ("username".to_string(), username.to_string()),
                ("application".to_string(), "rust-keyring".to_string()),
            ]),
            label: metadata,
        }),
        Platform::Windows => {
            if let Some(keychain) = target {
                PlatformCredential::Win(WinCredential {
                    // Note: Since Windows doesn't support multiple keychains,
                    // and since it's nice for clients to have control over
                    // the target_name directly, we use the `keychain` value
                    // as the target name if it's specified non-default.
                    username: username.to_string(),
                    target_name: keychain.to_string(),
                    target_alias: String::new(),
                    comment: metadata,
                })
            } else {
                PlatformCredential::Win(WinCredential {
                    // Note: default concatenation of user and service name is
                    // used because windows uses target_name as sole identifier.
                    // See the README for more rationale.  Also see this issue
                    // for Python: https://github.com/jaraco/keyring/issues/47
                    username: username.to_string(),
                    target_name: format!("{}.{}", username, service),
                    target_alias: String::new(),
                    comment: metadata,
                })
            }
        }
        Platform::MacOs => PlatformCredential::Mac(MacCredential {
            domain: target.into(),
            service: service.to_string(),
            account: username.to_string(),
        }),
        Platform::Ios => PlatformCredential::Ios(IosCredential {
            service: service.to_string(),
            account: username.to_string(),
        }),
    }
}
/// Create the default target credential for a keyring entry.  The caller
/// can provide an optional target parameter to influence the mapping.
Create the default target credential for a keyring entry.  The caller
can provide an optional target parameter to influence the mapping.
Create the default target credential for a keyring entry . The caller can provide an optional target parameter to influence the mapping .
pub fn default_target(
    platform: &Platform,
    target: Option<&str>,
    service: &str,
    username: &str,
) -> PlatformCredential {
    const VERSION: &str = env!("CARGO_PKG_VERSION");
    let custom = if target.is_none() {
        "entry"
    } else {
        "custom entry"
    };
    let metadata = format!(
        "keyring-rs v{} {} for service '{}', user '{}'",
        VERSION, custom, service, username
    );
    match platform {
        Platform::Linux => PlatformCredential::Linux(LinuxCredential {
            collection: target.unwrap_or("default").to_string(),
            attributes: HashMap::from([
                ("service".to_string(), service.to_string()),
                ("username".to_string(), username.to_string()),
                ("application".to_string(), "rust-keyring".to_string()),
            ]),
            label: metadata,
        }),
        Platform::Windows => {
            if let Some(keychain) = target {
                PlatformCredential::Win(WinCredential {
                    // Note: Since Windows doesn't support multiple keychains,
                    // and since it's nice for clients to have control over
                    // the target_name directly, we use the `keychain` value
                    // as the target name if it's specified non-default.
                    username: username.to_string(),
                    target_name: keychain.to_string(),
                    target_alias: String::new(),
                    comment: metadata,
                })
            } else {
                PlatformCredential::Win(WinCredential {
                    // Note: default concatenation of user and service name is
                    // used because windows uses target_name as sole identifier.
                    // See the README for more rationale.  Also see this issue
                    // for Python: https://github.com/jaraco/keyring/issues/47
                    username: username.to_string(),
                    target_name: format!("{}.{}", username, service),
                    target_alias: String::new(),
                    comment: metadata,
                })
            }
        }
        Platform::MacOs => PlatformCredential::Mac(MacCredential {
            domain: target.into(),
            service: service.to_string(),
            account: username.to_string(),
        }),
        Platform::Ios => PlatformCredential::Ios(IosCredential {
            service: service.to_string(),
            account: username.to_string(),
        }),
    }
}
pub fn default_target ( platform : & Platform , target : Option < & str > , service : & str , username : & str , ) -> PlatformCredential { const VERSION : & str = env ! ( " " ) ; let custom = if target . is_none ( ) { " " } else { " " } ; let metadata = format ! ( " " VERSION custom service username ) ; match platform { Platform :: Linux => PlatformCredential :: Linux ( LinuxCredential { collection : target . unwrap_or ( " " ) . to_string ( ) , attributes : HashMap :: from ( [ ( " " . to_string ( ) , service . to_string ( ) ) , ( " " . to_string ( ) , username . to_string ( ) ) , ( " " . to_string ( ) , " " . to_string ( ) ) , ] ) , label : metadata , } ) , Platform :: Windows => { if let Some ( keychain ) = target { PlatformCredential :: Win ( WinCredential { // Note: Since Windows doesn't support multiple keychains, // and since it's nice for clients to have control over // the target_name directly, we use the `keychain` value // as the target name if it's specified non-default. username : username . to_string ( ) , target_name : keychain . to_string ( ) , target_alias : String :: new ( ) , comment : metadata , } ) } else { PlatformCredential :: Win ( WinCredential { // Note: default concatenation of user and service name is // used because windows uses target_name as sole identifier. // See the README for more rationale.  Also see this issue // for Python: https://github.com/jaraco/keyring/issues/47 username : username . to_string ( ) , target_name : format ! ( " " username service ) , target_alias : String :: new ( ) , comment : metadata , } ) } } Platform :: MacOs => PlatformCredential :: Mac ( MacCredential { domain : target . into ( ) , service : service . to_string ( ) , account : username . to_string ( ) , } ) , Platform :: Ios => PlatformCredential :: Ios ( IosCredential { service : service . to_string ( ) , account : username . to_string ( ) , } ) , } }
Create the default target credential for a keyring entry.
Create the default target credential for a keyring entry .
platform
&Platform
target
Option<&str>
service
&str
username
&str