sl4f_lib/component/
types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use serde::{Deserialize, Serialize};

pub enum ComponentMethod {
    Launch,
    List,
    Search,
}

impl std::str::FromStr for ComponentMethod {
    type Err = anyhow::Error;
    fn from_str(method: &str) -> Result<Self, Self::Err> {
        match method {
            "Launch" => Ok(ComponentMethod::Launch),
            "List" => Ok(ComponentMethod::List),
            "Search" => Ok(ComponentMethod::Search),
            _ => return Err(format_err!("Invalid Component Facade method: {}", method)),
        }
    }
}

#[derive(Deserialize, Debug)]
pub struct ComponentSearchRequest {
    pub name: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentSearchResult {
    Success,
    NotFound,
}

#[derive(Deserialize, Debug)]
pub struct ComponentLaunchRequest {
    pub url: Option<String>,
    pub arguments: Option<Vec<String>>,
    pub wait_until_stop: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentLaunchResponse {
    Success,
    Fail(i64),
}