Skip to main content

RuntimeDetector

Struct RuntimeDetector 

Source
pub struct RuntimeDetector { /* private fields */ }
Expand description

Finds the runtime of a project: the first option, in the order they were added, that matches an input the way the Strategy says.

PHP: Utopia\Detector\Detector\Runtime.

use utopia_detector::{Node, Php, RuntimeDetector, Strategy};

let mut detector = RuntimeDetector::new(Strategy::Extension, "yarn");
detector.add_option(Php).add_option(Node);
detector.add_input("src/main.ts").add_input("Dockerfile");

let runtime = detector.detect().expect("a runtime");
assert_eq!(runtime.name(), "node");
assert_eq!(runtime.commands(), "yarn install");
use Utopia\Detector\Detection\Runtime\Node;
use Utopia\Detector\Detection\Runtime\PHP;
use Utopia\Detector\Detector\Runtime;
use Utopia\Detector\Detector\Strategy;

$detector = new Runtime(new Strategy(Strategy::EXTENSION), 'yarn');
$detector->addOption(new PHP())->addOption(new Node());
$detector->addInput('src/main.ts')->addInput('Dockerfile');

$runtime = $detector->detect();
echo $runtime->getName(), "\n";     // node
echo $runtime->getCommands(), "\n"; // yarn install

Implementations§

Source§

impl RuntimeDetector

Source

pub fn new(strategy: Strategy, packager: impl Into<String>) -> Self

A detector matching inputs by strategy, for a project using packager (pnpm when unsure).

PHP: new Runtime($strategy, $packager).

Source

pub fn add_option(&mut self, option: impl Runtime + 'static) -> &mut Self

Adds a runtime, tried after the others.

PHP: addOption($runtime).

Source

pub fn add_input(&mut self, input: impl Into<String>) -> &mut Self

Adds an input: a file name, or a language name for Strategy::Languages.

PHP: addInput($content).

Source

pub fn detect(&self) -> Option<Detected<'_, dyn Runtime>>

The first runtime matching an input, with the detector’s packager, or None.

PHP: detect(), which also sets the packager on the runtime it returns.

Trait Implementations§

Source§

impl Debug for RuntimeDetector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The strategy, packager, options’ names and inputs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.