#cross-platform #traits #engine #apps #shared #portable #system

narthex_engine_trait

Shared code (trait) for portable apps

3 releases

0.1.2 Oct 30, 2021
0.1.1 Sep 28, 2021
0.1.0 Sep 27, 2021

#72 in #portable

Download history 4/week @ 2024-02-18 24/week @ 2024-02-25 1/week @ 2024-03-03 4/week @ 2024-03-10 57/week @ 2024-03-31 1/week @ 2024-04-07

59 downloads per month
Used in narthex_web_app

MPL-2.0 license

11KB
69 lines

narthex-engine-trait

This crate provides the engine trait for a system that creates portable apps that run on both PCs and Android mobile phones.

For more information, see the API documentation at https://docs.rs/narthex_engine_trait/0.1.0/narthex_engine_trait/

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 https://mozilla.org/MPL/2.0/.


lib.rs:

This system enables building portable apps that run on both PCs and Android mobile phones.

There is an example repository that implements an example app (the classic Wumpus game) for both the PC and for Android mobile. The two platform implementations share a common back end ('engine') and otherwise use boilerplate code that differs little across applications.

Overall

The system contains the following parts, each of which is in a GitHub repository. This section describes which of these parts need to be changed to implement a different app. Some parts do not require any change, some parts are examples that should not require much change, and the the engine crate will need to be written to provide the functionality of the new app.

  • narthex-engine-trait defines [EngineTrait]; this should not require any change to implement a new app.
  • narthex-wumpus is an example of the use of this framework. See the GitHub page for narthex-wumpus for this. The narthex-wumpus repository contains:
  • engine crate contains the code to implement the wumpus game, this implements [EngineTrait].
  • wumpus crate is the front-end for the PC implementation of the game; this should require little change to implement a new app.
  • wumpus-c crate is C bindings for the engine crate; this should require little change to implement a new app.
  • Wumpus is the Android code (Java etc) for the Android implementation of the game; this should require little change to implement a new app.
  • narthex-web-app is some code that makes it easier to put together the PC implementation of the app; this should not require any change to implement a new app. See the narthex-web-app documentation for more information.

This page describes the [EngineTrait] interface between an Engine and a user interface. This crate should not require any change to implement a new app.

Creating an engine (overall architecture)

To create an app, you need to create the following types in your application. The engine (satisfies [EngineTrait]) does the application-specific functions.

  1. At the start, the user interface will create a web view (a browser) for the engine.
  2. The engine, at initialisation, is passed a Config (satisfies [ConfigTrait]) by the main program.
  3. The user interface will call engine.initial_html() and the engine must return an HTML string.
  4. Then, for each user input, the user interface passes an Action (satisfies [ActionTrait]) to the engine using engine.execute(action) and the engine must return a Response (satisfies [ResponseTrait]) back to the user interface.
  5. Also, for application event, the user interface passes an [Event] to the engine using engine.execute(action) and the engine must return a Response (satisfies [ResponseTrait]) back to the user interface.
  6. At the end, the engine will return a response with response.shutdown_required() and the user interface will terminate the application.

Dependencies

~2–2.8MB
~58K SLoC