Skip to content

Instantly share code, notes, and snippets.

@nacika-ins
Created November 21, 2015 10:22
Show Gist options
  • Save nacika-ins/f3c3e4c6b8ac1f267630 to your computer and use it in GitHub Desktop.
Save nacika-ins/f3c3e4c6b8ac1f267630 to your computer and use it in GitHub Desktop.
Rustで子が親を持つ
use google::GoogleAuthAccount;
use http::Client;
/* URL
-------------------------------------------------------------------------------*/
const URL_GOOGLE_PLUS: &'static str = "https://plus.google.com/";
/* GooglePlusは parent という寿命を持っている
-------------------------------------------------------------------------------*/
pub struct GooglePlus<'parent> {
/* parentは parent と同じ寿命を持つ
-------------------------------------------------------------------------------*/
parent: &'parent mut GoogleAuthAccount
}
impl<'parent> GooglePlus<'parent> {
/* 初期化メソッド
-------------------------------------------------------------------------------*/
pub fn new(parent: &mut GoogleAuthAccount) -> GooglePlus {
/* ミュータブルとしてクライアントを取得する
-------------------------------------------------------------------------------*/
match parent.client.as_mut() {
Some(client) => {
/* google plusのHTMLの取得
// -------------------------------------------------------------------------------*/
println!("--------------------- ここまで 🍔");
let mut body = client.get_body("http://google.com");
println!("--------------------- \x1b[33m{:?}\x1b[0m", body);
}
None => {}
};
/* クローンされたclientを移植
-------------------------------------------------------------------------------*/
let mut gp = GooglePlus {
parent: parent
};
/* google plus instance を渡す
-------------------------------------------------------------------------------*/
gp
}
/*
-------------------------------------------------------------------------------*/
pub fn post(&mut self, text: String) {
println!("-------------- SUCSESS!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment