summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-fixtures/callbacks/src/lib.rs
blob: 9ada66bca5ec6d2d73c35b814a2fe1776554a554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

trait Logger {
    fn log(&self, message: String);
    fn finished(&self);
}

fn log_even_numbers(logger: Box<dyn Logger>, items: Vec<i32>) {
    for i in items {
        if i % 2 == 0 {
            logger.log(format!("Saw even number: {i}"))
        }
    }
    logger.finished();
}

fn log_even_numbers_main_thread(logger: Box<dyn Logger>, items: Vec<i32>) {
    log_even_numbers(logger, items)
}

include!(concat!(env!("OUT_DIR"), "/callbacks.uniffi.rs"));