<commit_before>#![feature(core,env,os)]
extern crate "dbus-rs" as dbus;

use std::env::{args, set_exit_status};
use dbus::{Connection, BusType, Message, MessageItem};

const DEST: &'static str = "org.kde.kdeconnect";
const PATH: &'static str = "/modules/kdeconnect";

fn get_ids(c: &Connection) -> Result<Vec<String>, &'static str> {
    let mut m = Message::new_method_call(DEST
                                         , PATH
                                         , &*[DEST, "daemon"].connect(".")
                                         , "devices").unwrap();
    m.append_items(&[MessageItem::Bool(true)]); // onlyReachable
    m = c.send_with_reply_and_block(m, 1000).unwrap();
    match m.get_items()[0] {
        MessageItem::Array(_, 0) => Err("No reachable devices."),
        MessageItem::Array(ref a, _) => Ok(a.iter().map(|e| match e {
            &MessageItem::Str(ref s) => s.clone(),
            _ => unreachable!(),
        }).collect()),
        _ => unreachable!(),
    }
}

fn share_url(c: &Connection, id: &String, url: &String) {
    let mut m = Message::new_method_call(DEST
                                         , &*[PATH, "devices", &id[], "share"].connect("/")
                                         , &*[DEST, "device.share"].connect(".")
                                         , "shareUrl").unwrap();
    m.append_items(&[MessageItem::Str(url.clone())]);
    c.send_with_reply_and_block(m, 1000).unwrap();
}

fn main() {
    let args: Vec<_> = args().map(|oss| oss.into_string().unwrap()).collect();
    let urls = &args[1..];
    if urls.is_empty() {
        set_exit_status(1);
        return println!("Usage: {} url [url ...]", &args[0])
    }

    let ref c = Connection::get_private(BusType::Session).unwrap();
    match get_ids(c) {
        Err(e) => return println!("{}", e),
        Ok(ids) =>
            for url in urls.iter() {
                for id in (*ids).iter() {
                    share_url(c, id, url);
                }
            }
    }
}<commit_msg>assign as references<commit_after>#![feature(core,env,os)]
extern crate "dbus-rs" as dbus;

use std::env::{args, set_exit_status};
use dbus::{Connection, BusType, Message, MessageItem};

const DEST: &'static str = "org.kde.kdeconnect";
const PATH: &'static str = "/modules/kdeconnect";

fn get_ids(c: &Connection) -> Result<Vec<String>, &'static str> {
    let mut m = Message::new_method_call(DEST
                                         , PATH
                                         , &*[DEST, "daemon"].connect(".")
                                         , "devices").unwrap();
    m.append_items(&[MessageItem::Bool(true)]); // onlyReachable
    m = c.send_with_reply_and_block(m, 1000).unwrap();
    match m.get_items()[0] {
        MessageItem::Array(_, 0) => Err("No reachable devices."),
        MessageItem::Array(ref a, _) => Ok(a.iter().map(|e| match e {
            &MessageItem::Str(ref s) => s.clone(),
            _ => unreachable!(),
        }).collect()),
        _ => unreachable!(),
    }
}

fn share_url(c: &Connection, id: &String, url: &String) {
    let mut m = Message::new_method_call(DEST
                                         , &*[PATH, "devices", &id[], "share"].connect("/")
                                         , &*[DEST, "device.share"].connect(".")
                                         , "shareUrl").unwrap();
    m.append_items(&[MessageItem::Str(url.clone())]);
    c.send_with_reply_and_block(m, 1000).unwrap();
}

fn main() {
    let args: Vec<_> = args().map(|oss| oss.into_string().unwrap()).collect();
    let urls = &args[1..];
    if urls.is_empty() {
        set_exit_status(1);
        return println!("Usage: {} url [url ...]", &args[0])
    }

    let ref c = Connection::get_private(BusType::Session).unwrap();
    match get_ids(c) {
        Err(e) => return println!("{}", e),
        Ok(ref ids) =>
            for ref url in urls {
                for ref id in ids {
                    share_url(c, id, url);
                }
            }
    }
}
{'fraction_non_alphanumeric': 0.18048659384309831, 'fraction_numerical': 0.006454816285998014, 'mean_word_length': 1.9323144104803494, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1242178', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1247, 'n_words': 249}